前言
延續上一篇 w4560000 - Prometheus 學習筆記-3
本篇紀錄發送告警 Mail、Telegram 頻道
作業環境
Windows 10 Professional (22H2)
Docker Desktop
Docker Compose
設定說明
可參考原始碼 Github - w4560000
Alert Rule
alert_rules.yml
groups:
- name: example
rules:
- alert: net_input_rate_bps > 2000
expr: demo_recording_net_rate_bps > 2000
for: 10s
labels:
severity: warn
annotations:
description: 接收封包達到上限, net_input_rate_bps = {{ $value }}
- name: example2
rules:
- alert: net_input_rate_bps > 4000
expr: demo_recording_net_rate_bps > 4000
for: 10s
labels:
severity: urgent
annotations:
description: 接收封包達到上限, net_input_rate_bps = {{ $value }}
alertManager.yml
route:
receiver: "email-default"
group_wait: 5s #收發訊息等待時間
group_interval: 10s #相同 Group 發送告警時間間隔
repeat_interval: 30m #告警時間間隔
routes:
- receiver: "email-default"
continue: true # EMail 發送完後,後續 receiver 接續發送告警
- receiver: "telegram-warn"
match_re: # regex
severity: warn
- receiver: "telegram-urgent"
match:
severity: urgent
receivers:
- name: email-default
email_configs:
- to: leozheng0411@gmail.com
from: leozheng0411@gmail.com
smarthost: smtp.gmail.com:587
auth_username: leozheng0411@gmail.com
auth_identity: leozheng0411@gmail.com
auth_password: qkusqlmdneapgzsu
send_resolved: true
- name: telegram-warn
telegram_configs:
- chat_id: -1002030473502
bot_token: "6765457318:AAG47n_tNSvTijh8MN24__9hAwDs2zsL94U"
message: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"
send_resolved: true
- name: telegram-urgent
telegram_configs:
- chat_id: -1002016569477
bot_token: "6765457318:AAG47n_tNSvTijh8MN24__9hAwDs2zsL94U"
message: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"
send_resolved: true
Telegram Bot、頻道相關設定請參考 w4560000 - .Net Core 推送訊息至 Telegram Channel
操作流程
參考 w4560000 - Prometheus 學習筆記-3
參考文件
Prometheus - email_config
Prometheus - telegram_config
轉載請註明來源,若有任何錯誤或表達不清楚的地方,歡迎在下方評論區留言,也可以來信至 leozheng0621@gmail.com
如果文章對您有幫助,歡迎斗內(donate),請我喝杯咖啡