前提
已经部署Grafana,并且dashboard接入数据
大屏编号地址:Node Exporter Full | Grafana Labs

创建企微机器人

备注:群里若有第三方外部人员不能创建



机器人创建完成,记录下来Webhook地址
Grafana配置告警消息模板


bash
{{ define "KDDI" }}
{{ range $i,$alert :=.Alerts }}
===KDDI资源使用率监控报警===
告警状态:{{ if eq .Status "firing" }} <font color="#FF0000">触发告警</font> {{ else if eq .Status "resolved" }} <font color="#00FF00">告警解除</font>{{ end }}
告警级别:{{ .Labels.level }}
告警类型:{{ .Labels.alertname }}
故障主机:{{ if eq .Labels.instance "123.56.222.147:9100" }} <font color="#0000FF" style="font-weight:bold;">123.56.222.147</font> {{ else if eq .Labels.instance "47.94.168.75:9100" }} <font color="#0000FF" style="font-weight:bold;">47.94.168.75</font>{{ end }}
告警主题:{{ .Annotations.summary }}
告警详情:{{ .Annotations.description }}
触发时间:{{ .StartsAt.Local.Format "2006-01-02 15:40:12" }}
==========end==========
{{ end }}
{{ end }}
Grafana配置企微机器人



选择告警消息模板,配置告警title,保存
Grafana配置panelCPU告警规则(阈值80)



bash
100 - (avg by (instance,job)(irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)



保存退出

查看企微告警消息

内存和磁盘配置跟CPU基本一样,查询语句分别如下

bash
CPU
100 - (avg by (instance,job)(irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
内存
(1 - (node_memory_MemAvailable_bytes)/node_memory_MemTotal_bytes)* 100
磁盘
100-(node_filesystem_free_bytes{fstype=~"ext4|xfs"}/node_filesystem_size_bytes {fstype=~"ext4|xfs"}*100)