我的应用程序的每个实例都有一个不同的URL。
如何配置prometheus.yml,使其采用目标路径以及主机名?

scrape_configs:
- job_name:       'example-random'

# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s

static_configs:
  - targets: ['localhost:8090','localhost:8080']
    labels:
      group: 'dummy'

最佳答案

您目前无法在作业中为每个目标配置metrics_path,但是可以为每个目标创建单独的作业,以便可以为每个目标定义metrics_path

您的配置文件如下所示:

scrape_configs:
- job_name:       'example-target-1'
  scrape_interval: 5s
  metrics_path: /target-1-path-to-metrics
  static_configs:
    - targets: ['localhost:8090']
      labels:
        group: 'dummy'

- job_name:       'example-target-2'
  scrape_interval: 5s
  metrics_path: /totally-different-path-for-target-2
  static_configs:
    - targets: ['localhost:8080']
      labels:
        group: 'dummy-2'

关于prometheus - 每个目标使用不同的Prometheus抓取网址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44927130/

10-15 21:00