我的应用程序的每个实例都有不同的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)
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)
这是我用来启动和运行 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)
| 归档时间: |
|
| 查看次数: |
11710 次 |
| 最近记录: |