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