docker - 无法通过警报管理器发送电子邮件
问题描述
docker-compose.yml:服务已启动并正在运行。
version: '3'
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- 9090:9090
volumes:
- ./prometheus/conf:/etc/prometheus
# - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./alertmanager/alert_rules.yml:/alertmanager/alert.rules.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
alertmanager:
image: prom/alertmanager:latest
container_name: alertmanager
ports:
- 9093:9093
volumes:
- ./alertmanager/:/etc/alertmanager/
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
- '--storage.path=/alertmanager'
prometheus.yml:带有目标和警报目标集的 Prometheus 配置文件。alertmanager 目标 url 工作正常。
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
- 10.10.5.14:9093
scheme: http
timeout: 10s
api_version: v1
rule_files:
- "/alertmanager/alert.rules:/alertmanager/alert.rules"
scrape_configs:
- job_name: 'blackbox'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- "google.com"
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9115
alert.rules:标准警报规则。
groups:
- name: example
rules:
# Alert for any instance that is unreachable for >1 minutes.
- alert: InstanceDown
expr: up == 0
for: 1m
alertmanager.yml:通过 gmail smtp 发送警报的代码。
route:
group_by: [Alertname]
# Send all notifications to me.
receiver: email-me
receivers:
- name: email-me
email_configs:
- to: anyemail.com
from: senderlogin@gmail.com
smarthost: smtp.gmail.com:587
auth_username: "senderlogin@gmail.com"
auth_identity: "senderlogin@gmail.com"
auth_password: "password"
问题:所有容器都在工作,但普罗米修斯规则中没有规则。而且这些字母也不是相应的。我无法理解我错过了什么。欢迎任何提示。谢谢。 在此处输入图像描述 在此处 输入图像描述
解决方案
从 prometheus 容器的角度来看,Alertmanager 不在 localhost 上,网络在容器中命名空间,因此您需要使用 DNS 发现联系 alertmanager 以查找当前容器 IP。使用 compose,会自动为服务名称配置 DNS,在这种情况下alertmanager
:
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
推荐阅读
- selenium - 在 for 循环中添加 WebDriverWait 的问题 - selenium
- bash - 在 bash 中理解 bc
- linux - 在函数调用中注册的更改
- python - 从 AWS Lambda Python 访问 GCP 计算定价 API
- python - 如何在 python 中使用 url
- node.js - 如何从后端的端点返回 json 数据
- java - 时间片、上下文切换和线程干扰之间的区别
- powershell - 如何找到哪个嵌套循环是优秀的
- python - 使用 Selenium 和 Beautifulsoup 进行 Python 抓取无法提取嵌套标签,错误对象不可调用
- xpsdocument - 如何通过修改 .gpd 文件将 pasersize 添加到 Microsoft XPS 文档编写器