You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 01:35:27