Prometheus 指标终点是 运行 但目标状态为 down
Prometheus metrics end point is running but the target status is down
我在 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 版本与另一个完全隔离。
要解决此问题,请尝试 运行 将两个容器放在同一个 docker-compose.yaml
中,使用容器名称而不是 localhost
。
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 中出现的。
我在 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 版本与另一个完全隔离。
要解决此问题,请尝试 运行 将两个容器放在同一个 docker-compose.yaml
中,使用容器名称而不是 localhost
。
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 中出现的。