Alertmanager docker 容器拒绝连接
Alertmanager docker container refuses connections
我有一个 docker-compose 文件,其中包含一个 django 应用程序、Prometheus 监控容器和 Alertmanager 容器。
所有构建都很好,应用 运行,Prometheus 正在监控,但当它要发出警报时,警报没有到达 Alertmanager 容器,并显示以下错误消息:
prometheus_1 | level=error ts=2021-08-02T08:58:16.018Z caller=notifier.go:527 component=notifier alertmanager=http://0.0.0.0:9093/api/v2/alerts count=1 msg="Error sending alert" err="Post \"http://0.0.0.0:9093/api/v2/alerts\": dial tc
p 0.0.0.0:9093: connect: connection refused"
Alertmanager 也像这样拒绝 telnet 测试连接
klex@DESKTOP-PVC5EP:~$ telnet 0.0.0.0 9093
Trying 0.0.0.0...
Connected to 0.0.0.0.
Escape character is '^]'.
Connection closed by foreign host.
docker-compose 文件是:
version: "3"
services:
web:
container_name: smsgate
build: .
command: sh -c "python manage.py migrate &&
python manage.py collectstatic --no-input &&
python manage.py runserver 0.0.0.0:15001"
volumes:
- .:/smsgate:rw
- static_volume:/home/app/smsgate/static
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "15001:15001"
env_file:
- .env.prod
image: smsgate
restart: "always"
networks:
- promnet
prometheus:
image: prom/prometheus
volumes:
- ./prometheus/:/etc/prometheus/
depends_on:
- alertmanager
ports:
- "9090:9090"
networks:
- promnet
alertmanager:
image: prom/alertmanager
ports:
- "9093:9093"
volumes:
- ./alertmanager/:/etc/alertmanager/
restart: "always"
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
networks:
- promnet
volumes:
static_volume:
alertmanager_volume:
prometheus_volume:
networks:
promnet:
driver: bridge
而prometheus.yml配置文件是
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
- "0.0.0.0:9093"
rule_files:
- alert.rules.yml
scrape_configs:
- job_name: monitoring
metrics_path: /metrics
static_configs:
- targets:
- smsgate:15001
很有可能有网络?配置问题,因为该服务似乎不接受任何连接。
Prometheus和Alertmanager GUI界面可以通过浏览器访问
http://127.0.0.1:9090/
和
http://127.0.0.1:9093/
分别
如有任何帮助,我们将不胜感激。
尝试使用 服务名称 而不是 0.0.0.0
。将警报块配置中的最后一行更改为:
alerting:
alertmanagers:
- static_configs:
- targets:
- "alertmanager:9093"
考虑到它们在同一个网络上,它应该可以工作 fin
更新
我一开始就误解了这个问题。道歉。请检查上面更新的区块☝
我有一个 docker-compose 文件,其中包含一个 django 应用程序、Prometheus 监控容器和 Alertmanager 容器。
所有构建都很好,应用 运行,Prometheus 正在监控,但当它要发出警报时,警报没有到达 Alertmanager 容器,并显示以下错误消息:
prometheus_1 | level=error ts=2021-08-02T08:58:16.018Z caller=notifier.go:527 component=notifier alertmanager=http://0.0.0.0:9093/api/v2/alerts count=1 msg="Error sending alert" err="Post \"http://0.0.0.0:9093/api/v2/alerts\": dial tc
p 0.0.0.0:9093: connect: connection refused"
Alertmanager 也像这样拒绝 telnet 测试连接
klex@DESKTOP-PVC5EP:~$ telnet 0.0.0.0 9093
Trying 0.0.0.0...
Connected to 0.0.0.0.
Escape character is '^]'.
Connection closed by foreign host.
docker-compose 文件是:
version: "3"
services:
web:
container_name: smsgate
build: .
command: sh -c "python manage.py migrate &&
python manage.py collectstatic --no-input &&
python manage.py runserver 0.0.0.0:15001"
volumes:
- .:/smsgate:rw
- static_volume:/home/app/smsgate/static
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "15001:15001"
env_file:
- .env.prod
image: smsgate
restart: "always"
networks:
- promnet
prometheus:
image: prom/prometheus
volumes:
- ./prometheus/:/etc/prometheus/
depends_on:
- alertmanager
ports:
- "9090:9090"
networks:
- promnet
alertmanager:
image: prom/alertmanager
ports:
- "9093:9093"
volumes:
- ./alertmanager/:/etc/alertmanager/
restart: "always"
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
networks:
- promnet
volumes:
static_volume:
alertmanager_volume:
prometheus_volume:
networks:
promnet:
driver: bridge
而prometheus.yml配置文件是
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
- "0.0.0.0:9093"
rule_files:
- alert.rules.yml
scrape_configs:
- job_name: monitoring
metrics_path: /metrics
static_configs:
- targets:
- smsgate:15001
很有可能有网络?配置问题,因为该服务似乎不接受任何连接。
Prometheus和Alertmanager GUI界面可以通过浏览器访问
http://127.0.0.1:9090/
和
http://127.0.0.1:9093/
分别
如有任何帮助,我们将不胜感激。
尝试使用 服务名称 而不是 0.0.0.0
。将警报块配置中的最后一行更改为:
alerting:
alertmanagers:
- static_configs:
- targets:
- "alertmanager:9093"
考虑到它们在同一个网络上,它应该可以工作 fin
更新
我一开始就误解了这个问题。道歉。请检查上面更新的区块☝