Grafana配置告警
规则配置
- 修改Grafana默认配置
[root@prometheus ~]# vim /usr/local/Prometheus_grafana/conf/defaults.ini
# domain参数改为Grafana主机IP
domain = 192.168.137.130
# 找到并修改以下配置
[smtp]
enabled = true
host = smtp.126.com:25
user = "XXXXXXXXXX@126.com"
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = "XXXXXXXXXXXXXXXX"
cert_file =
key_file =
skip_verify = true
from_address = XXXXXXXXXXX@126.com
from_name = Grafana
ehlo_identity =
startTLS_policy =
- 在Dashboard中配置Alert
# 参数详解
Rule
Name "CPU usage alert" Evaluate every "30s" For "1m"
- Name # 规则名
- Evaluate every # 每次刮擦间隔
- For # 设置持续超出设定值的时间,触发告警
Conditions
WHEN "avg()" OF "query(A,10s,now)" IS ABOVE "90"
- WHEN # 规则类型,avg()代表时间段内平均值
- OF # A为默认,示例表示十秒前到现在的值
- IS ABOVE # 在WHEN与OF设置的时间段内,值大于90,触发告警
Notifications
Send to "Notifications告警组"
Message "告警内容"
配置告警组
- 'Alerting' --> 'Notification channels' --> 'New channel'
邮件告警
NAME
Notifications告警组名
Type
Email
Addresses
要发送到的邮箱地址
Optional Email settings
[]Single email # 向所有收件人发送一封电子邮件
Notification settings
[]Default # 将此通知设为默认
[]Include image # 捕获图像并将其包含在通知中
[]Disable Resolve Message # 禁用警报状态返回为false时发送的解析消息[OK]
[]Send reminders # 静默配置,设置间隔多久发送一次告警
DINGDING告警
- 在钉钉中创建一个告警群组
- "群设置" --> "智能群助手" --> "添加机器人" --> "Webhook机器人"
- 必选项有安全设置,可以选择grafana的IP地址段,示例中选择的自定义关键词,选择Notifications告警组名中的“告警”为关键词。
- 添加机器人后,会给出一个Webhook地址,切勿泄露
NAME
Notifications告警组名
Type
DingDing
Url
Webhook的地址
Optional Email settings
[]Message Type # 目前只支持Link
Notification settings
[]Default # 将此通知设为默认
[]Include image # 捕获图像并将其包含在通知中
[]Disable Resolve Message # 禁用警报状态返回为false时发送的解析消息[OK]
[]Send reminders # 静默配置,设置间隔多久发送一次告警