mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Replace example config with new YAML format.
This commit is contained in:
parent
5fbde88919
commit
86087120dd
|
@ -66,7 +66,7 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default DNS SD configuration.
|
// The default DNS SD configuration.
|
||||||
DefaultDNSConfig = DefaultedDNSConfig{
|
DefaultDNSSDConfig = DefaultedDNSSDConfig{
|
||||||
RefreshInterval: Duration(30 * time.Second),
|
RefreshInterval: Duration(30 * time.Second),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -80,7 +80,7 @@ type Config struct {
|
||||||
original string
|
original string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) String() string {
|
func (c Config) String() string {
|
||||||
if c.original != "" {
|
if c.original != "" {
|
||||||
return c.original
|
return c.original
|
||||||
}
|
}
|
||||||
|
@ -117,12 +117,12 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
|
||||||
// DefaultedConfig is a proxy type for Config.
|
// DefaultedConfig is a proxy type for Config.
|
||||||
type DefaultedConfig struct {
|
type DefaultedConfig struct {
|
||||||
GlobalConfig *GlobalConfig `yaml:"global_config"`
|
GlobalConfig *GlobalConfig `yaml:"global"`
|
||||||
RuleFiles []string `yaml:"rule_files,omitempty"`
|
RuleFiles []string `yaml:"rule_files,omitempty"`
|
||||||
ScrapeConfigs []*ScrapeConfig `yaml:"scrape_configs,omitempty"`
|
ScrapeConfigs []*ScrapeConfig `yaml:"scrape_configs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalConfig configures values that used across other configuration
|
// GlobalConfig configures values that are used across other configuration
|
||||||
// objects.
|
// objects.
|
||||||
type GlobalConfig struct {
|
type GlobalConfig struct {
|
||||||
// DefaultedGlobalConfig contains the actual fields for GlobalConfig.
|
// DefaultedGlobalConfig contains the actual fields for GlobalConfig.
|
||||||
|
@ -141,11 +141,11 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
// DefaultedGlobalConfig is a proxy type for GlobalConfig.
|
// DefaultedGlobalConfig is a proxy type for GlobalConfig.
|
||||||
type DefaultedGlobalConfig struct {
|
type DefaultedGlobalConfig struct {
|
||||||
// How frequently to scrape targets by default.
|
// How frequently to scrape targets by default.
|
||||||
ScrapeInterval Duration `yaml:"scrape_interval"`
|
ScrapeInterval Duration `yaml:"scrape_interval,omitempty"`
|
||||||
// The default timeout when scraping targets.
|
// The default timeout when scraping targets.
|
||||||
ScrapeTimeout Duration `yaml:"scrape_timeout"`
|
ScrapeTimeout Duration `yaml:"scrape_timeout,omitempty"`
|
||||||
// How frequently to evaluate rules by default.
|
// How frequently to evaluate rules by default.
|
||||||
EvaluationInterval Duration `yaml:"evaluation_interval"`
|
EvaluationInterval Duration `yaml:"evaluation_interval,omitempty"`
|
||||||
|
|
||||||
// The labels to add to any timeseries that this Prometheus instance scrapes.
|
// The labels to add to any timeseries that this Prometheus instance scrapes.
|
||||||
Labels clientmodel.LabelSet `yaml:"labels,omitempty"`
|
Labels clientmodel.LabelSet `yaml:"labels,omitempty"`
|
||||||
|
@ -175,18 +175,18 @@ type DefaultedScrapeConfig struct {
|
||||||
// The job name to which the job label is set by default.
|
// The job name to which the job label is set by default.
|
||||||
JobName string `yaml:"job_name"`
|
JobName string `yaml:"job_name"`
|
||||||
// How frequently to scrape the targets of this scrape config.
|
// How frequently to scrape the targets of this scrape config.
|
||||||
ScrapeInterval Duration `yaml:"scrape_interval"`
|
ScrapeInterval Duration `yaml:"scrape_interval,omitempty"`
|
||||||
// The timeout for scraping targets of this config.
|
// The timeout for scraping targets of this config.
|
||||||
ScrapeTimeout Duration `yaml:"scrape_timeout"`
|
ScrapeTimeout Duration `yaml:"scrape_timeout,omitempty"`
|
||||||
// The HTTP resource path on which to fetch metrics from targets.
|
// The HTTP resource path on which to fetch metrics from targets.
|
||||||
MetricsPath string `yaml:"metrics_path"`
|
MetricsPath string `yaml:"metrics_path,omitempty"`
|
||||||
// The URL scheme with which to fetch metrics from targets.
|
// The URL scheme with which to fetch metrics from targets.
|
||||||
Scheme string `yaml:"scheme"`
|
Scheme string `yaml:"scheme,omitempty"`
|
||||||
|
|
||||||
// List of labeled target groups for this job.
|
// List of labeled target groups for this job.
|
||||||
TargetGroups []*TargetGroup `yaml:"target_groups,omitempty"`
|
TargetGroups []*TargetGroup `yaml:"target_groups,omitempty"`
|
||||||
// List of DNS service discovery configurations.
|
// List of DNS service discovery configurations.
|
||||||
DNSConfigs []*DNSConfig `yaml:"dns_configs,omitempty"`
|
DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"`
|
||||||
// List of relabel configurations.
|
// List of relabel configurations.
|
||||||
RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"`
|
RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ type TargetGroup struct {
|
||||||
Source string `yaml:"-", json:"-"`
|
Source string `yaml:"-", json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tg *TargetGroup) String() string {
|
func (tg TargetGroup) String() string {
|
||||||
return tg.Source
|
return tg.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,29 +229,44 @@ func (tg *TargetGroup) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DNSConfig is the configuration for DNS based service discovery.
|
// MarshalYAML implements the yaml.Marshaller interface.
|
||||||
type DNSConfig struct {
|
func (tg TargetGroup) MarshalYAML() (interface{}, error) {
|
||||||
// DefaultedDNSConfig contains the actual fields for DNSConfig.
|
g := &struct {
|
||||||
DefaultedDNSConfig `yaml:",inline"`
|
Targets []string `yaml:"targets"`
|
||||||
|
Labels clientmodel.LabelSet `yaml:"labels,omitempty"`
|
||||||
|
}{
|
||||||
|
Targets: make([]string, 0, len(tg.Targets)),
|
||||||
|
Labels: tg.Labels,
|
||||||
|
}
|
||||||
|
for _, t := range tg.Targets {
|
||||||
|
g.Targets = append(g.Targets, string(t[clientmodel.AddressLabel]))
|
||||||
|
}
|
||||||
|
return g, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DNSSDConfig is the configuration for DNS based service discovery.
|
||||||
|
type DNSSDConfig struct {
|
||||||
|
// DefaultedDNSSDConfig contains the actual fields for DNSSDConfig.
|
||||||
|
DefaultedDNSSDConfig `yaml:",inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalYAML implements the yaml.Unmarshaller interface.
|
// UnmarshalYAML implements the yaml.Unmarshaller interface.
|
||||||
func (c *DNSConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (c *DNSSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
c.DefaultedDNSConfig = DefaultDNSConfig
|
c.DefaultedDNSSDConfig = DefaultDNSSDConfig
|
||||||
err := unmarshal(&c.DefaultedDNSConfig)
|
err := unmarshal(&c.DefaultedDNSSDConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(c.Names) == 0 {
|
if len(c.Names) == 0 {
|
||||||
return fmt.Errorf("DNS config must contain at least one SRV server name")
|
return fmt.Errorf("DNS config must contain at least one SRV record name")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultedDNSConfig is a proxy type for DNSConfig.
|
// DefaultedDNSSDConfig is a proxy type for DNSSDConfig.
|
||||||
type DefaultedDNSConfig struct {
|
type DefaultedDNSSDConfig struct {
|
||||||
Names []string `yaml:"names"`
|
Names []string `yaml:"names"`
|
||||||
RefreshInterval Duration `yaml:"refresh_interval"`
|
RefreshInterval Duration `yaml:"refresh_interval,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RelabelAction is the action to be performed on relabeling.
|
// RelabelAction is the action to be performed on relabeling.
|
||||||
|
@ -298,7 +313,7 @@ type DefaultedRelabelConfig struct {
|
||||||
// with the configured separator in order.
|
// with the configured separator in order.
|
||||||
SourceLabels clientmodel.LabelNames `yaml:"source_labels,flow"`
|
SourceLabels clientmodel.LabelNames `yaml:"source_labels,flow"`
|
||||||
// Separator is the string between concatenated values from the source labels.
|
// Separator is the string between concatenated values from the source labels.
|
||||||
Separator string `yaml:"separator"`
|
Separator string `yaml:"separator,omitempty"`
|
||||||
// Regex against which the concatenation is matched.
|
// Regex against which the concatenation is matched.
|
||||||
Regex *Regexp `yaml:"regex"`
|
Regex *Regexp `yaml:"regex"`
|
||||||
// The label to which the resulting string is written in a replacement.
|
// The label to which the resulting string is written in a replacement.
|
||||||
|
@ -306,7 +321,7 @@ type DefaultedRelabelConfig struct {
|
||||||
// Replacement is the regex replacement pattern to be used.
|
// Replacement is the regex replacement pattern to be used.
|
||||||
Replacement string `yaml:"replacement,omitempty"`
|
Replacement string `yaml:"replacement,omitempty"`
|
||||||
// Action is the action to be performed for the relabeling.
|
// Action is the action to be performed for the relabeling.
|
||||||
Action RelabelAction `yaml:"action"`
|
Action RelabelAction `yaml:"action,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regexp encapsulates a regexp.Regexp and makes it YAML marshallable.
|
// Regexp encapsulates a regexp.Regexp and makes it YAML marshallable.
|
||||||
|
@ -329,7 +344,7 @@ func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalYAML implements the yaml.Marshaller interface.
|
// MarshalYAML implements the yaml.Marshaller interface.
|
||||||
func (re *Regexp) MarshalYAML() (interface{}, error) {
|
func (re Regexp) MarshalYAML() (interface{}, error) {
|
||||||
return re.String(), nil
|
return re.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,15 +72,15 @@ var expectedConf = &Config{DefaultedConfig{
|
||||||
MetricsPath: "/my_path",
|
MetricsPath: "/my_path",
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
|
|
||||||
DNSConfigs: []*DNSConfig{
|
DNSSDConfigs: []*DNSSDConfig{
|
||||||
{DefaultedDNSConfig{
|
{DefaultedDNSSDConfig{
|
||||||
Names: []string{
|
Names: []string{
|
||||||
"first.dns.address.domain.com",
|
"first.dns.address.domain.com",
|
||||||
"second.dns.address.domain.com",
|
"second.dns.address.domain.com",
|
||||||
},
|
},
|
||||||
RefreshInterval: Duration(15 * time.Second),
|
RefreshInterval: Duration(15 * time.Second),
|
||||||
}},
|
}},
|
||||||
{DefaultedDNSConfig{
|
{DefaultedDNSSDConfig{
|
||||||
Names: []string{
|
Names: []string{
|
||||||
"first.dns.address.domain.com",
|
"first.dns.address.domain.com",
|
||||||
},
|
},
|
||||||
|
|
4
config/testdata/conf.good.yml
vendored
4
config/testdata/conf.good.yml
vendored
|
@ -1,5 +1,5 @@
|
||||||
# my global config
|
# my global config
|
||||||
global_config:
|
global:
|
||||||
scrape_interval: 15s
|
scrape_interval: 15s
|
||||||
evaluation_interval: 30s
|
evaluation_interval: 30s
|
||||||
# scrape_timeout is set to the global default (10s).
|
# scrape_timeout is set to the global default (10s).
|
||||||
|
@ -46,7 +46,7 @@ scrape_configs:
|
||||||
metrics_path: /my_path
|
metrics_path: /my_path
|
||||||
# scheme defaults to 'http'.
|
# scheme defaults to 'http'.
|
||||||
|
|
||||||
dns_configs:
|
dns_sd_configs:
|
||||||
- refresh_interval: 15s
|
- refresh_interval: 15s
|
||||||
names:
|
names:
|
||||||
- first.dns.address.domain.com
|
- first.dns.address.domain.com
|
||||||
|
|
2
config/testdata/labelname.bad.yml
vendored
2
config/testdata/labelname.bad.yml
vendored
|
@ -1,3 +1,3 @@
|
||||||
global_config:
|
global:
|
||||||
labels:
|
labels:
|
||||||
not$allowed: value
|
not$allowed: value
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
# Global default settings.
|
|
||||||
global {
|
|
||||||
scrape_interval: "15s" # By default, scrape targets every 15 seconds.
|
|
||||||
evaluation_interval: "15s" # By default, evaluate rules every 15 seconds.
|
|
||||||
|
|
||||||
# Attach these extra labels to all timeseries collected by this Prometheus instance.
|
|
||||||
labels: {
|
|
||||||
label: {
|
|
||||||
name: "monitor"
|
|
||||||
value: "codelab-monitor"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load and evaluate rules in this file every 'evaluation_interval' seconds. This field may be repeated.
|
|
||||||
#rule_file: "prometheus.rules"
|
|
||||||
}
|
|
||||||
|
|
||||||
# A job definition containing exactly one endpoint to scrape: Here it's prometheus itself.
|
|
||||||
job: {
|
|
||||||
# The job name is added as a label `job={job-name}` to any timeseries scraped from this job.
|
|
||||||
name: "prometheus"
|
|
||||||
# Override the global default and scrape targets from this job every 5 seconds.
|
|
||||||
scrape_interval: "5s"
|
|
||||||
|
|
||||||
# Let's define a group of targets to scrape for this job. In this case, only one.
|
|
||||||
target_group: {
|
|
||||||
# These endpoints are scraped via HTTP.
|
|
||||||
target: "http://localhost:9090/metrics"
|
|
||||||
}
|
|
||||||
}
|
|
30
documentation/examples/prometheus.yml
Normal file
30
documentation/examples/prometheus.yml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# my global config
|
||||||
|
global_config:
|
||||||
|
scrape_interval: 15s # By default, scrape targets every 15 seconds.
|
||||||
|
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
|
||||||
|
# scrape_timeout is set to the global default (10s).
|
||||||
|
|
||||||
|
# Attach these extra labels to all timeseries collected by this Prometheus instance.
|
||||||
|
labels:
|
||||||
|
monitor: codelab-monitor
|
||||||
|
|
||||||
|
# Load and evaluate rules in this file every 'evaluation_interval' seconds.
|
||||||
|
rule_files:
|
||||||
|
# - "first.rules"
|
||||||
|
# - "second.rules"
|
||||||
|
|
||||||
|
# A scrape configuration containing exactly one endpoint to scrape:
|
||||||
|
# Here it's Prometheus itself.
|
||||||
|
scrape_configs:
|
||||||
|
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
|
||||||
|
- job_name: prometheus
|
||||||
|
|
||||||
|
# Override the global default and scrape targets from this job every 5 seconds.
|
||||||
|
scrape_interval: 5s
|
||||||
|
scrape_timeout: 10s
|
||||||
|
|
||||||
|
# metrics_path defaults to '/metrics'
|
||||||
|
# scheme defaults to 'http'.
|
||||||
|
|
||||||
|
target_groups:
|
||||||
|
- targets: ['localhost:9090']
|
|
@ -360,7 +360,7 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc
|
||||||
func ProvidersFromConfig(cfg *config.ScrapeConfig) ([]TargetProvider, error) {
|
func ProvidersFromConfig(cfg *config.ScrapeConfig) ([]TargetProvider, error) {
|
||||||
var providers []TargetProvider
|
var providers []TargetProvider
|
||||||
|
|
||||||
for _, dnscfg := range cfg.DNSConfigs {
|
for _, dnscfg := range cfg.DNSSDConfigs {
|
||||||
dnsSD := discovery.NewDNSDiscovery(dnscfg.Names, time.Duration(dnscfg.RefreshInterval))
|
dnsSD := discovery.NewDNSDiscovery(dnscfg.Names, time.Duration(dnscfg.RefreshInterval))
|
||||||
providers = append(providers, dnsSD)
|
providers = append(providers, dnsSD)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue