全局配置

global 属于全局的默认配置,它主要包含 4 个属性,

  • scrape_interval: 拉取 targets 的默认时间间隔。
  • scrape_timeout: 拉取一个 target 的超时时间。
  • evaluation_interval: 执行 rules 的时间间隔。
  • external_labels: 额外的属性,会添加到拉取的数据并存到数据库中。

其代码结构体定义为:

  1. // GlobalConfig configures values that are used across other configuration
  2. // objects.
  3. type GlobalConfig struct {
  4. // How frequently to scrape targets by default.
  5. ScrapeInterval model.Duration `yaml:"scrape_interval,omitempty"`
  6. // The default timeout when scraping targets.
  7. ScrapeTimeout model.Duration `yaml:"scrape_timeout,omitempty"`
  8. // How frequently to evaluate rules by default.
  9. EvaluationInterval model.Duration `yaml:"evaluation_interval,omitempty"`
  10. // The labels to add to any timeseries that this Prometheus instance scrapes.
  11. ExternalLabels model.LabelSet `yaml:"external_labels,omitempty"`
  12. // Catches all undefined fields and must be empty after parsing.
  13. XXX map[string]interface{} `yaml:",inline"`
  14. }

配置文件结构大概为:

  1. global:
  2. scrape_interval: 15s # By default, scrape targets every 15 seconds.
  3. evaluation_interval: 15s # By default, scrape targets every 15 seconds.
  4. scrape_timeout: 10s # is set to the global default (10s).
  5. # Attach these labels to any time series or alerts when communicating with
  6. # external systems (federation, remote storage, Alertmanager).
  7. external_labels:
  8. monitor: 'codelab-monitor'