咱们这里选择 email 告警,首先修改 grafana 的配置文件 /etc/grafana/grafana.ini
,找到 SMTP 部分,修改成以下:node
[smtp] ;enabled = false enabled = true ;host = localhost:25 host = smtp.exmail.qq.com:25 ;user = user = notice@wzlinux.com # If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;""" ;password = password = Q7P1hsdfsenzzyM ;cert_file = ;key_file = ;skip_verify = false ;from_address = admin@grafana.localhost from_address = notice@wzlinux.com from_name = Grafana # EHLO identity in SMTP dialog (defaults to instance_name) ;ehlo_identity = dashboard.example.com
修改完成后,重启 grafana。linux
登录到 grafana 中,建立一个通知渠道,测试一下,看看是否收到邮件。sql
30s
, 3m
, 5m
or 1h
.grafana 不支持带有变量的模板报警,因此咱们须要建立一个不带有变量的模板,这个咱们能够去官方的 dashboard 中找一个,我这里找到编号为5984
,你们能够安装这个模板。ide
我在里面简单修改了一下格式,以及数据源,主要是针对 CPU 的负载修改了一下,其余资源默承认以使用。测试
我这边已经测试过了,没有什么问题,报警均可以正常运行,我把 promSQL 贴出来this
100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
legend 设置为{{instance}}
3d
100*(node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Buffers_bytes - node_memory_Cached_bytes) / node_memory_MemTotal_bytes
legend 设置为{{instance}}
code
100.0 - 100 * ((node_filesystem_avail_bytes / 1000 / 1000 ) / (node_filesystem_size_bytes / 1024 / 1024))
legend 设置为 {{instance}} - {{mountpoint}}
blog
如下拿 CPU 的配置截图给你们看下:ip
Queries:
Visualization:
Alert: