首页 > 解决方案 > Prometheus:是否可以在配置文件中为 job_name>static_configs>targets 编写正则表达式

问题描述

我有一个监控服务器集群的 prometheus.yml 配置文件。配置文件看起来像这样:

    global:
      scrape_interval:     15s # By default, scrape targets every 15 seconds.

    scrape_configs:

      - job_name: 'prometheus'
        scrape_interval: 5s
        scrape_timeout: 5s
        static_configs:
          - targets: ['localhost:9090']

      - job_name: minio
        metrics_path: /minio/prometheus/metrics
        scheme: http
        static_configs:
          - targets: [ "server-01.example.com:9000", "server-02.example.com:9000", "server-03.example.com:9000", "server-04.example.com:9000" ]
# Upto 32 such servers in the cluster server-{01..32}.example.com:9000

我讨厌在配置文件中指定每个目标。有没有办法可以为目标编写正则表达式,server-{01..32}.example.com:9000而不是指定列表中的每个服务器。我尝试了不同的方法来做到这一点,但没有一个对我有用。

标签: monitoringprometheusmetrics

解决方案


推荐阅读