安装alertmanager
https://prometheus.io/download/
百度云:
链接:https://pan.baidu.com/s/14_IGKeh7wj5uvbkbEqcTRg
提取码:4mqm
解压对应的tar.gz包
tar -zxvf alertmanager-0.21.0.linux-amd64.tar.gz
配置alertmanager
获取smtp_auth_password:
修改alertmanager.yml(smtp_auth_password就是刚才获得的授权码,而不是qq密码)
global:
resolve_timeout: 5m
smtp_smarthost: 'smtp.qq.com:465'
smtp_from: 'XXXXXXX@qq.com'
smtp_auth_username: 'XXXXXXXX@qq.com'
smtp_auth_password: 'XXXXXXXXX'
smtp_require_tls: false
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'mail-receiver'
receivers:
- name: 'mail-receiver'
email_configs:
- to: 'XXXXXXXXXX@qq.com'
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
启动alertmanager:
nohup ./alertmanager --config.file=alertmanager.yml &
配置prometheus
配置prometheus:(在prometheus根目录下新建rule.yml,并配置)
touch rule.yml
文件内容:(这里的job名承接上一篇)
groups:
- name: alert-rule
rules:
- alert: JobDown
expr: sum(up{job="springboot"}) == 0
for: 1m
labels:
severity: critical
修改prometheus配置文件:
vi prometheus.yml
需要修改两处
修改完毕后,重启prometheus,启动完成后,我们可以看到我们添加的rules,在status中。
包括告警:
关闭springboot服务后,我们发现告警状态变为pending.
最后变成firing状态:
这时候,我收到了邮箱: