一、部署、配置钉钉告警插件
配置钉钉机器人请参阅: https://blog.csdn.net/knight_zhou/article/details/105583741
1.1 部署prometheus-webhook-dingtalk 钉钉告警插件
1 | [admin@prometheus prometheus]$ wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v1.4.0/prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz |
1 | [admin@prometheus prometheus]$ docker pull timonwong/prometheus-webhook-dingtalk |
1.2 配置prometheus-webhook-dingtalk
1 | [admin@prometheus prometheus-webhook-dingtalk]$ cp config.example.yml config.yml |
1.3 配置 告警模板
1 | [admin@prometheus prometheus-webhook-dingtalk]$ cat contrib/templates/dingding.tmpl |
遇到的问题:刚开始发往钉钉的消息都显示成一行了,特别不好看;
在这里需要在告警消息后面留4个空格,例如:
1 **告警主题:** {{ .Labels.alertname | upper }}
1.4 启动服务
1 | [admin@prometheus prometheus-webhook-dingtalk]$ ./prometheus-webhook-dingtalk --ding.profile="webhook1=https://oapi.dingtalk.com/robot/send?access_token={替换成自己的dingding token}" |
或使用supervisor启动服务
1 | [program:prometheus-webhook-dingtalk] |
二、配置prometheus报警规则
1 | groups: |
重启prometheus服务
1 | [admin@prometheus prometheus]$ curl -X POST http://127.0.0.1:9090/-/reload |
supervisor启动配置
1 | [program:prometheus] |
三、配置alertmanager
1 | global: |
重启alertmanager服务
supervisor启动配置
1 | [program:alertmanager] |
告警效果如下: