每个目标的不同刮取URL

poo*_*abh 10 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:8090','localhost:8080']
    labels:
      group: 'dummy'
Run Code Online (Sandbox Code Playgroud)

Yar*_*hiy 14

我通过使用file_sd_config选项实现了这一点。所有目标都在单独的文件中描述,文件可以是 YML 或 JSON 格式。

普罗米修斯.yml :

scrape_configs:
  - job_name: 'dummy'  # This will be overridden in targets.yml
    file_sd_configs:
      - files:
        - targets.yml
Run Code Online (Sandbox Code Playgroud)

目标.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
Run Code Online (Sandbox Code Playgroud)

  • 您可以在没有 **file_sd_configs** 的情况下使用 **__metrics_path__**,只需在 **static_configs** (2认同)

Oli*_*ver 11

您当前无法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'
Run Code Online (Sandbox Code Playgroud)


Ven*_*kat 7

这是我用来启动和运行 prometheus 的配置。

普罗米修斯端点: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'

Run Code Online (Sandbox Code Playgroud)


Con*_*orB 6

我相信您需要对__metrics_path__标签集进行一些重新标记以包含应用程序的不同路径。

Prometheus配置文档在这里证明对您很有用,这篇文章应该可以帮助您更好地理解重新标记。

  • 对于想要示例的人,这里有一个:/sf/ask/4190643971/ (2认同)