Prometheus Metrics 端点正在运行,但目标状态为 down

标签 prometheus

我在 http://localhost:9615/metrics 上运行 Prometheus Polkadot 指标端点 我已经在配置 prometheus.yml 中定义了

global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:
  # - "first.rules"
  # - "second.rules"

scrape_configs:
  - job_name: "prometheus"
    scrape_interval: 5s
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: "substrate_node"
    scrape_interval: 5s
    static_configs:
      - targets: ["localhost:9615"]

我在目标中遇到以下错误

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

enter image description here

我的 Prometheus 正在 Docker 容器内运行

docker run -d --name prometheus -p 9090:9090 -v prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml

如何解决该错误?

最佳答案

为了在两个容器之间进行通信,您需要它们位于同一个 Docker 桥接网络中。否则,一个容器的 localhost 版本与另一个容器完全隔离。

要解决此问题,请尝试使用容器名称而不是 localhost 在同一个 docker-compose.yaml 中运行两个容器。

By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

version: '2'

services:
  polkadot:
    container_name: polkadot
    image: parity/polkadot
    ports:
      - 30333:30333 # p2p port
      - 9933:9933 # rpc port
      - 9944:9944 # ws port
      - 9615:9615
    command: [
      "--name", "PolkaDocker",
      "--ws-external",
      "--rpc-external",
      "--rpc-cors", "all",
      "--prometheus-external"
    ]

  prometheus:
    container_name: prometheus
    image: prom/prometheus
    ports:
      - 9090:9090
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    command: [
      "--config.file=/etc/prometheus/prometheus.yml"
    ]

同样,您需要更新您在 prometheus 配置中点击的主机,如下所示:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:
  # - "first.rules"
  # - "second.rules"

scrape_configs:
  - job_name: "prometheus"
    scrape_interval: 5s
    static_configs:
      - targets: ["prometheus:9090"] # NOTE HOW ITS NOT LOCALHOST HERE
  - job_name: "substrate_node"
    scrape_interval: 5s
    static_configs:
      - targets: ["polkadot:9615"] # NOTE HOW ITS NOT LOCALHOST HERE

您可以在他们的文档 here 中找到有关 Docker 网络复杂性的大量资源。 。但是上面的配置应该可以让你启动并运行,因为这两个目标都出现在我的 Prometheus 中。

关于Prometheus Metrics 端点正在运行,但目标状态为 down,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68674413/

相关文章:

python - 我如何首先根据它们的单位(bit/s、Kbit/s 等)对特定的字典列表进行排序,然后根据它们的值对它们进行排序

prometheus - Spring boot 2.3.4 - Kafka 指标在/actuator/prometheus 中不可见

monitoring - 超过上下文截止日期 - 普罗米修斯

java - 将 java-List<T> 转换为可与 iomicrometer 的 MultiGauge 一起使用的流

service - 在 kubernetes 命名空间中监控 prometheus 上的自定义服务时出现问题

kubernetes - 在 Prometheus Alertmanager 上设置 MicrosoftTeams 通知

prometheus - 使用 PromQL 计算可用性

prometheus - 如何在 Alertmanager 中向一个接收者组发送多个警报?

prometheus - Akka Stream 和 Kamon-Prometheus 不返回任何指标但加载一个空页面

kubernetes - 如何配置 kube-prometheus-stack helm 安装来抓取 Kubernetes 服务?