prometheus 无法从本地主机访问指标

2 node.js docker-compose prometheus

我一直在尝试配置 prometheus 以在 grafana 中为我的 Nodejs 应用程序显示指标。对于指标,我使用 prom-client。但是,在本地主机上我总是收到以下错误:

Get http://localhost:5000/metrics: dial tcp 127.0.0.1:5000: connect: connection refused
Run Code Online (Sandbox Code Playgroud)

此外,如果我使用本地隧道服务,例如 ngrok,它将能够读取指标。我缺少什么?我需要在某处添加一些特殊配置?

这是我的 prometheus.yml 文件:

global:
    scrape_interval: 5s
    external_labels:
        monitor: 'my-monitor'
scrape_configs:
    - job_name: 'prometheus'
      static_configs:
               - targets: ['localhost:9090']
    - job_name: 'my-app'
      static_configs:
               - targets: ['localhost:5000']
Run Code Online (Sandbox Code Playgroud)

我正在使用 docker-compose 运行默认的 prometheus 镜像,grafana 也是如此。

huy*_*mha 8

因为您正在使用docker-compose,因此localhost127.0.0.1将无法在 docker 容器中工作。

你可以替换localhost你的机器IP或者像你一样使用ngrok ,docker可以将其解析为你的IP。

感谢您的阅读:D