通过一个简单的实验介绍如何通过 Email 接受告警。
假设该实验运行在本地机器上
其中一些关键配置如下:
global:
smtp_smarthost: 'smtp.qq.com:587'
smtp_from: 'xxx@qq.com'
smtp_auth_username: 'xxx@qq.com'
smtp_auth_password: 'your_email_password'
smtp_require_tls: false
route:
repeat_interval: 10s
receiver: team-X-mails
receivers:
- name: 'team-X-mails'
email_configs:
- to: 'team-X+alerts@example.org'
alert.rules
文件文件中写入以下简单规则作为示例。
groups:
- name: example
rules:
- alert: HighRequestLatency
expr: job:request_latency_seconds:mean5m{job="myjob"} > 0.5
for: 15s
annotations:
summary: High request latency
prometheus.yml
文件将规则添加进去:
rule_files:
- "alert.rules"
启动AlertManager服务
./Alertmanager --config.file=simple.yml
启动prometheus服务
./prometheus --Alertmanager.url=http://localhost:9093
根据以上步骤设置,此时 “team-X+alerts@example.org” 应该就可以收到 “xxx@qq.com” 发送的告警邮件了。