mirror of
https://github.com/prometheus/prometheus
synced 2024-12-24 23:42:32 +00:00
Add Consul SD configuration.
This commit is contained in:
parent
ab4e3ee594
commit
b0c181dc0d
@ -78,6 +78,12 @@ var (
|
||||
DefaultFileSDConfig = DefaultedFileSDConfig{
|
||||
RefreshInterval: Duration(30 * time.Second),
|
||||
}
|
||||
|
||||
// The default Consul SD configuration.
|
||||
DefaultConsulSDConfig = DefaultedConsulSDConfig{
|
||||
TagSeparator: ",",
|
||||
Scheme: "http",
|
||||
}
|
||||
)
|
||||
|
||||
// Config is the top-level configuration for Prometheus's config files.
|
||||
@ -200,6 +206,8 @@ type DefaultedScrapeConfig struct {
|
||||
DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"`
|
||||
// List of file service discovery configurations.
|
||||
FileSDConfigs []*FileSDConfig `yaml:"file_sd_configs,omitempty"`
|
||||
// List of Consul service discovery configurations.
|
||||
ConsulSDConfigs []*ConsulSDConfig `yaml:"consul_sd_configs,omitempty"`
|
||||
// List of relabel configurations.
|
||||
RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"`
|
||||
}
|
||||
@ -340,6 +348,40 @@ type DefaultedFileSDConfig struct {
|
||||
RefreshInterval Duration `yaml:"refresh_interval,omitempty"`
|
||||
}
|
||||
|
||||
// ConsulSDConfig is the configuration for Consul service discovery.
|
||||
type ConsulSDConfig struct {
|
||||
// DefaultedConsulSDConfig contains the actual fields for ConsulSDConfig.
|
||||
DefaultedConsulSDConfig `yaml:",inline"`
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the yaml.Unmarshaller interface.
|
||||
func (c *ConsulSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
c.DefaultedConsulSDConfig = DefaultConsulSDConfig
|
||||
err := unmarshal(&c.DefaultedConsulSDConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(c.Server) == "" {
|
||||
return fmt.Errorf("Consul SD configuration requires a server address")
|
||||
}
|
||||
if len(c.Services) == 0 {
|
||||
return fmt.Errorf("Consul SD configuration requires at least one service name")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultedConsulSDConfig is a proxy type for ConsulSDConfig.
|
||||
type DefaultedConsulSDConfig struct {
|
||||
Server string `yaml:"server"`
|
||||
Token string `yaml:"token"`
|
||||
Datacenter string `yaml:"datacenter"`
|
||||
TagSeparator string `yaml:"tag_separator"`
|
||||
Scheme string `yaml:"scheme"`
|
||||
Username string `yaml:"username"`
|
||||
Password string `yaml:"password"`
|
||||
Services []string `yaml:"services"`
|
||||
}
|
||||
|
||||
// RelabelAction is the action to be performed on relabeling.
|
||||
type RelabelAction string
|
||||
|
||||
|
@ -361,6 +361,9 @@ func ProvidersFromConfig(cfg *config.ScrapeConfig) []TargetProvider {
|
||||
for _, c := range cfg.FileSDConfigs {
|
||||
providers = append(providers, discovery.NewFileDiscovery(c))
|
||||
}
|
||||
for _, c := range cfg.ConsulSDConfigs {
|
||||
providers = append(providers, discovery.NewConsulDiscovery(c))
|
||||
}
|
||||
if len(cfg.TargetGroups) > 0 {
|
||||
providers = append(providers, NewStaticProvider(cfg.TargetGroups))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user