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

Ubuntu中Prometheus无法抓取Windows本地SpringBoot指标的问题

问题原因及解决方法

根本原因

Ubuntu系统中的localhost(对应127.0.0.1)指向的是Ubuntu自身的本地回环地址,而你的SpringBoot应用运行在Windows系统上,Prometheus尝试连接自己的8080端口,自然会出现连接拒绝的错误。

解决步骤

1. 获取Windows的局域网IP地址

在Windows系统中:

  • 按下Win+R,输入cmd打开命令提示符
  • 执行命令ipconfig,找到当前网络(以太网/WLAN)对应的IPv4地址,例如192.168.3.105

2. 调整SpringBoot的监听配置

修改SpringBoot的application.yml,让应用监听所有网卡(允许局域网访问):

server:
  address: 0.0.0.0
management:
  endpoints:
    web:
      exposure:
        include: prometheus

修改后重启SpringBoot应用。

3. 更新Prometheus的抓取配置

修改Ubuntu上的prometheus.yml,将targets中的localhost:8080替换为Windows的局域网IP加端口:

scrape_configs:
  - job_name: "services"
    static_configs:
      - targets: ["192.168.3.105:8080"] # 替换为你的Windows IPv4地址
    metrics_path: '/actuator/prometheus'

修改后重启Prometheus服务。

4. 检查Windows防火墙设置

确保Windows防火墙允许8080端口的入站连接:

  • 打开Windows Defender防火墙,进入「高级设置」
  • 添加一条入站规则,允许TCP协议的8080端口通过;或者临时关闭防火墙进行测试(测试完成后记得重新开启并添加规则)

5. 验证网络连通性

在Ubuntu终端执行以下命令,测试是否能正常访问SpringBoot的指标接口:

curl http://192.168.3.105:8080/actuator/prometheus

如果返回指标数据,说明网络连通正常,此时刷新Prometheus界面即可看到target状态变为up。

内容的提问来源于stack exchange,提问作者userdr725

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 08:15:37