无法使用 Prometheus 捕获客户端指标

Cannot capture client metrics with Prometheus

我有一个新手问题。

我正在使用 dockprom (github.com/stefanprodan/dockprom) 从 docker-compose 成功捕获指标。

现在我正在尝试使用 golang 的 Prometheus 客户端库监控我的应用程序的特定指标,但 Prometheus 将我的端点显示为关闭 (0),并在目标部分显示消息

Get http://localhost:8090/metrics: dial tcp 127.0.0.1:8090: connect: connection refused

但是,如果我导航到 http://localhost:8090/metrics,我可以看到公开的指标。

Prometheus 运行 在 docker-compose 一组容器中,而我的应用程序 运行 在另一个容器中。

我的端点在prometheus/prometheus.yml 中的声明是:

job_name: 'cloud_server_auth'

scrape_interval: 10s

static_configs:

targets: ['localhost:8090']

我注意到 cAdvisor 在 privileged_mode 中未 运行 时失败,但即使在修复该问题后,我仍然无法让普罗米修斯使用我的指标。

有什么想法吗?

提前感谢任何可能对这个问题有所了解的人,如果您需要任何进一步的信息,请告诉我。 阿道夫

如果你是 运行 Prometheus 在 Docker 容器中,那么当 Prometheus 调用其他地方收集指标时,localhost 是相对于 Prometheus 容器解释的,它也就是说,Prometheus 正在尝试从自身收集指标。

如果这是同一个 docker-compose.yml 文件中的全部 运行 那么您可以使用其他容器的 Docker Compose services: 名称作为主机名( s) 配置指标目标时。目标容器不一定需要发布 ports:,并且您需要使用容器内进程 运行 开启的端口号 – 如果您的 ports: 将容器端口重新映射到不同的主机端口,使用 second(容器)端口号,而不是第一个(主机)。

这与同一 docker-compose.yml 文件中的其他服务到服务调用的设置相同。 Networking in Compose 有关于容器网络环境的更多细节。