提问者:小点点

Prometheus metrics终端正在运行但目标状态已关闭


我在配置prometheus. yml中定义的http://localhost:9615/metrics运行Prometheus Polkadot指标endpoint

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"]

我在目标中得到了以下错误

获取"http://localhost:9615/metrics":拨tcp127.0.0.1:9615: connect:连接被拒绝

我的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

如何解决该错误?


共1个答案

匿名用户

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

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

默认情况下,Comput为您的应用设置一个网络。服务的每个容器都加入默认网络,并且该网络上的其他容器都可以访问,并且可以通过与容器名称相同的主机名被它们发现。

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

你可以在这里的文档中找到大量关于Docker网络复杂性的资源。但是上面的配置应该能让你启动并运行,因为这两个目标都是在我这边的普罗米修斯中出现的。