尝试使用Prometheus的file_sd_configs

试着使用file_sd_configs进行尝试。

请将以下内容用中文本地化改写,只需要提供一种版本:

版本

Prometheus 服务器版本:1.8.0。

请用中文进行参照。

static_config和file_sd_configs的区别

对于 static_configs,添加监视目标后需要重新启动 Prometheus 服务器。
对于 file_sd_configs,添加监视目标后会在一定时间(默认为5分钟)后自动加载配置,并立即将其添加为监视目标。

将targets列表写在一个名为prometheus.yml(默认名称)的文件中而不是直接写在里面,然后在file_sd_config中指定该文件,以便读取targets。- files作为路径读取时,是相对于执行目录的相对路径,因此如果是以./prometheus进行执行,- files只需要指定文件名即可。

设置示例

請將以下內容以中文進行同義語改寫,只需一個選項:

prometheus.yml

Prometheus配置文件

以下是使用prometheus.yml文件的file_sd_configs配置示例。

请注意,这是对文本进行的机器翻译,可能不完全准确。

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'codelab-monitor'

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first.rules"
  # - "second.rules"
  - 'prometheus.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'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'file_sd' # 任意の名前
    file_sd_configs:
      - files: # 複数のファイルを読み込ませることができる。
        - /usr/local/prometheus-server/file_sd1.yml
        - /usr/local/prometheus-server/file_sd2.yml

文档

文件的示例使用

- targets:
    - 192.168.10.10:9100
    - 192.168.10.11:9100
    - 192.168.10.12:9100
  labels:
    service: web
    role: role-1

- targets:
    - 192.168.20.10:9100
    - 192.168.20.11:9100
    - 192.168.20.12:9100
  labels:
    service: db
    role: role-2

确认状态

可以确认已经将带有标签的目标集成到具有job_name:“file_sd”的监视目标中,这是在prometheus.yml文件中进行配置时产生的。

2017-10-26_18h17_04

如果手动添加对照或者定期将对照添加到cron流程中,则可以暂时实现对自动调整功能的支持。

广告
将在 10 秒后关闭
bannerAds