Prometheus无法抓取Docker部署的SpringBoot应用指标问题排查
问题:Prometheus无法抓取Docker部署的SpringBoot应用指标
环境与部署情况
我在服务器上通过Docker部署了以下服务:
- SpringBoot应用:端口18081
- Grafana:端口3001
- PostgreSQL:端口5432
- Prometheus:端口9090
Prometheus配置文件(prometheus.yml)
#My global config global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 rule_files: # - "first_rules.yml" # - "second_rules.yml" scrape_configs: - job_name: prometheus static_configs: - targets: ['localhost:9090'] - job_name: spring-actuator scrape_interval: 5s scrape_timeout: 5s metrics_path: /actuator/prometheus scheme: http static_configs: - targets: ['172.30.0.9:18081']
其中172.30.0.9是通过命令docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container-id>获取的SpringBoot应用Docker内部IP。
问题详情
- 访问Prometheus仪表盘(服务器IP:9090),发现Prometheus自身的抓取任务成功,但无法抓取SpringBoot应用的
/actuator/prometheus端点 - 在VM主机上执行
curl http://172.30.0.9:18081/actuator/prometheus可以成功获取所有Prometheus指标
已尝试的目标地址
我已尝试将SpringBoot应用的抓取目标地址设置为以下几种形式,但Prometheus仍无法正常访问该端点:
- localhost:18081
- 服务器公网IP:18081
- 容器名称:18081
- host.docker.internal:18081
提问
请问我是否遗漏了某些配置?
内容的提问来源于stack exchange,提问作者BadProgrammer
相关产品推荐
相关产品推荐

