Prometheus 监控报警系统 AlertManager 之邮件告警 (5)

然后,修改 AlertManager 启动命令,将本地 email.tmpl 文件挂载到容器内指定位置并重启。

$ docker run -d --name alertmanager -p 9093:9093 -v /root/prometheus/alertmanager.yml:/etc/alertmanager/alertmanager.yml -v /root/prometheus/alertmanager-tmpl/:/etc/alertmanager-tmpl/ prom/alertmanager:latest

上边模板中由于配置了 {{ .Annotations.description }} 变量,而之前 node-up.rules 中并没有配置该变量,会导致获取不到值,所以这里我们修改一下 node-up.rules 并重启 Promethues 服务。

$ vim /root/prometheus/rules/node-up.rules groups: - name: node-up rules: - alert: node-up expr: up{job="node-exporter"} == 0 for: 15s labels: severity: 1 team: node annotations: summary: "{{ $labels.instance }} 已停止运行!" description: "{{ $labels.instance }} 检测到异常停止!请重点关注!!!"

重启完毕后,同样模拟触发报警条件(停止 node-exporter 服务),也是可以正常发送模板邮件出来的,这次就是我们想要的风格啦!

img

当然我们还可以配置邮件标题,这里就不在演示了,详细配置可参考 。这里除了监控节点是否存活外,还可以监控很多很多指标,例如 CPU 负载告警、Mem 使用量告警、Disk 存储空间告警、Network 负载告警等等,这些都可以通过自定义 PromQL 表达式验证值来定义一些列的告警规则,来丰富日常工作中需要的各种告警。 这里,我们只演示了如何通过 AlertManager 来配置发送邮件告警,其他的告警方式,可以参考 官网文档 来配置,这里就不再演示了。下一篇,我们继续通过 Prometheus 来监控 SpringBoot 工程应用程序 JVM 情况,以及自定义 metrics 来实现特定功能的监控。

参考资料

prometheus docs

prometheus configuration

alertting configuration

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgfzsz.html