Prometheus 不同的普罗米修斯抓取每个目标的URL

Prometheus 不同的普罗米修斯抓取每个目标的URL,prometheus,Prometheus,我的应用程序的每个实例都有一个不同的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:8

我的应用程序的每个实例都有一个不同的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'

我认为您需要重新标记
\uuuuuu metrics\uu path\uuuu
标签集,以包含应用程序的各种路径


普罗米修斯在这里会对你很有用,应该会帮助你更好地理解重新标记。

你目前无法在作业中为每个目标配置
度量路径
,但你可以为每个目标创建单独的作业,这样你就可以为每个目标定义
度量路径

您的配置文件如下所示:

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'
我通过使用option实现了这一点。所有目标都在单独的文件中描述,这些文件可以是YML或JSON格式

普罗米修斯.yml:

scrape_configs:
  - job_name: 'dummy'  # This will be overridden in targets.yml
    file_sd_configs:
      - files:
        - targets.yml
- targets: ['host1:9999']
  labels:
    job: my_job
    __metrics_path__: /path1

- targets: ['host2:9999']
  labels:
    job: my_job  # can belong to the same job
    __metrics_path__: /path2
目标。yml

scrape_configs:
  - job_name: 'dummy'  # This will be overridden in targets.yml
    file_sd_configs:
      - files:
        - targets.yml
- targets: ['host1:9999']
  labels:
    job: my_job
    __metrics_path__: /path1

- targets: ['host2:9999']
  labels:
    job: my_job  # can belong to the same job
    __metrics_path__: /path2

这是我用来让普罗米修斯启动和运行的配置

普罗米修斯终点:
http://localhost:8080/appcontext/v1/actuator/prometheus

配置:在
/etc/prometheus/prometheus.yml

- job_name: 'appdev'
    scrape_interval: 5s
    metrics_path: /appcontext/v1/actuator/prometheus
    static_configs:
      - targets: ['localhost:8082'] 
        labels:
          group: 'appdev'


多亏了你的评论,我解决了动态更新scrape URL的问题。遗憾的是,它隐藏在文档中复杂的解释之下,而我认为这应该作为一项功能明确说明。对于想要举例的人,这里有一个例子:您可以使用“度量”路径,而不需要文件sd配置,只需在静态配置中,为什么这个Prometheus端点在端口8080上运行,而目标在8082上。不一定要一样吗?