如何在prometheus.yml中配置多个抓取URL?配置问题求助
正确的Prometheus采集配置方案
问题分析
你当前的配置存在关键错误:
- node_exporter端口写错:你提供的node_exporter指标地址是
localhost:9182/metrics,但配置里写的是localhost:9100,这会导致无法采集node_exporter的指标 - 多组件混在同一job里虽可行,但拆分job更便于后续监控维护(可选优化)
推荐配置(拆分job,清晰易维护)
scrape_configs: # 采集Prometheus自身指标 - job_name: "prometheus" metrics_path: "/metrics" static_configs: - targets: ["localhost:9090"] labels: group: 'system' # 采集node_exporter指标 - job_name: "node_exporter" metrics_path: "/metrics" static_configs: - targets: ["localhost:9182"] labels: group: 'system' # 采集Wildfly自身指标 - job_name: "wildfly" metrics_path: "/metrics" static_configs: - targets: ["localhost:9990"] labels: group: 'system' # 采集Wildfly内应用的指标 - job_name: "application" metrics_path: "/application/rest/metrics" static_configs: - targets: ["localhost:8080"] labels: group: 'application'
简化修正版(保留原job结构,仅修复端口错误)
scrape_configs: - job_name: "prometheus" metrics_path: "/metrics" static_configs: - targets: ["localhost:9182", "localhost:9990", "localhost:9090"] labels: group: 'system' - job_name: "application" metrics_path: "/application/rest/metrics" static_configs: - targets: ["localhost:8080"] labels: group: 'application'
验证步骤
- 修改配置后重启Prometheus服务
- 访问Prometheus UI(默认
http://localhost:9090),进入Status -> Targets页面,确认所有target状态为UP - 若某个target显示
DOWN,直接点击对应的Endpoint链接,确认指标接口是否能正常返回数据
内容的提问来源于stack exchange,提问作者Christian13467
相关产品推荐
相关产品推荐

