配置

Prometheus 启动的时候,可以加载运行参数 -config.file 指定配置文件,默认为 prometheus.yml

在配置文件中我们可以指定 global, alerting, rule_files, scrape_configs, remote_write, remote_read 等属性。

其代码结构体定义为:

  1. // Config is the top-level configuration for Prometheus's config files.
  2. type Config struct {
  3. GlobalConfig GlobalConfig `yaml:"global"`
  4. AlertingConfig AlertingConfig `yaml:"alerting,omitempty"`
  5. RuleFiles []string `yaml:"rule_files,omitempty"`
  6. ScrapeConfigs []*ScrapeConfig `yaml:"scrape_configs,omitempty"`
  7. RemoteWriteConfigs []*RemoteWriteConfig `yaml:"remote_write,omitempty"`
  8. RemoteReadConfigs []*RemoteReadConfig `yaml:"remote_read,omitempty"`
  9. // Catches all undefined fields and must be empty after parsing.
  10. XXX map[string]interface{} `yaml:",inline"`
  11. // original is the input from which the config was parsed.
  12. original string
  13. }

配置文件结构大概为:

  1. global:
  2. # How frequently to scrape targets by default.
  3. [ scrape_interval: <duration> | default = 1m ]
  4. # How long until a scrape request times out.
  5. [ scrape_timeout: <duration> | default = 10s ]
  6. # How frequently to evaluate rules.
  7. [ evaluation_interval: <duration> | default = 1m ]
  8. # The labels to add to any time series or alerts when communicating with
  9. # external systems (federation, remote storage, Alertmanager).
  10. external_labels:
  11. [ <labelname>: <labelvalue> ... ]
  12. # Rule files specifies a list of globs. Rules and alerts are read from
  13. # all matching files.
  14. rule_files:
  15. [ - <filepath_glob> ... ]
  16. # A list of scrape configurations.
  17. scrape_configs:
  18. [ - <scrape_config> ... ]
  19. # Alerting specifies settings related to the Alertmanager.
  20. alerting:
  21. alert_relabel_configs:
  22. [ - <relabel_config> ... ]
  23. alertmanagers:
  24. [ - <alertmanager_config> ... ]
  25. # Settings related to the experimental remote write feature.
  26. remote_write:
  27. [ - <remote_write> ... ]
  28. # Settings related to the experimental remote read feature.
  29. remote_read:
  30. [ - <remote_read> ... ]