分組
概述
分組將類似性質的警報分類為單個通知。當許多系統同時發生故障並且可能同時觸發數百到數千個警報時,這在較大的中斷期間尤其有用。
示例:當發生網絡分區時,集群中正在運行數十個或數百個服務實例。您的一半服務實例無法再訪問數據庫。Prometheus 中的警報規則被配置為在每個服務實例無法與數據庫通信時發送警報。因此,數百個警報被發送到 Alertmanager。
作為用戶,您只想獲得一個頁面,同時仍然能夠准確查看哪些服務實例受到影響。因此,可以將 Alertmanager 配置為按集群和警報名稱對警報進行分組,以便它發送單個緊湊通知。
警報分組、分組通知的時間以及這些通知的接收者由配置文件中的路由樹進行配置。
在 route 段中進行配置。
配置參數
route: group_by: ['alertname', 'app'] # 分組時使用的標簽,默認情況下,所有的告警都組織在一起,而一旦指定分組標簽,則Alertmanager將按這些標簽進行分組; group_wait: 30s # 發出一組告警通知的初始等待時長;允許等待一個抑制告警到達或收集屬於同一組的更多初始告警,通常是0到數分鍾; group_interval: 40s # 發送關於新告警的消息之前,需要等待多久;新告警將被添加到已經發送了初始通知的告警組中;一般在5分鍾或以上; repeat_interval: 1m # 成功發送了告警后再次發送告警信息需要等待的時長,一般至少為3個小時;
配置示例
route: group_by: ['alertname', 'app'] group_wait: 30s group_interval: 40s repeat_interval: 1m
alertmanage前端查看
抑制
抑制是一個概念,如果某些其他警報已經觸發,則抑制某些警報的通知。
示例:發出警報,通知無法訪問整個集群。如果該特定警報正在觸發,Alertmanager 可以配置為靜音與該集群相關的所有其他警報。這可以防止收到與實際問題無關的數百或數千個觸發警報的通知。
禁止通過 Alertmanager 的配置文件進行配置。
當存在與另一組匹配器匹配的警報(源)時,禁止匹配的規則進行告警(靜默)。對於equal
列表中的標簽名稱,目標警報和源警報都必須具有相同的標簽值。
從語義上講,缺少標簽和帶有空值的標簽是一回事。因此,如果equal
源警報和目標警報中都缺少 中列出的所有標簽名稱,則將應用禁止規則。
配置參數
# DEPRECATED: Use target_matchers below. # Matchers that have to be fulfilled in the alerts to be muted. # 目標報警字符串匹配 target_match: [ <labelname>: <labelvalue>, ... ] # DEPRECATED: Use target_matchers below. # 目標報警正則匹配 target_match_re: [ <labelname>: <regex>, ... ] # A list of matchers that have to be fulfilled by the target # alerts to be muted. # 目標報警的匹配列表 target_matchers: [ - <matcher> ... ] # DEPRECATED: Use source_matchers below. # Matchers for which one or more alerts have to exist for the # inhibition to take effect. # 源報警字符串匹配 source_match: [ <labelname>: <labelvalue>, ... ] # DEPRECATED: Use source_matchers below. # 源報警正則匹配器 source_match_re: [ <labelname>: <regex>, ... ] # A list of matchers for which one or more alerts have # to exist for the inhibition to take effect. # 源報警列表匹配器 source_matchers: [ - <matcher> ... ] # Labels that must have an equal value in the source and target # alert for the inhibition to take effect. # 匹配標簽 [ equal: '[' <labelname>, ... ']' ]
配置示例
alertmanage配置示例
inhibit_rules: - source_match: severity: 'critical' target_match_re: severity: '.*' equal: ['instance']
prometheus alert rule 配置示例
- alert: 主機內存不足 expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 99 for: 10s labels: severity: "critical" annotations: summary: 主機內存不足 (主機地址 {{ $labels.instance }}) description: "主機內存已滿 當前內存小於百分之70\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" - alert: warning 測試內存 expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 98 for: 10s labels: severity: "warning" annotations: summary: warning 主機內存不足 (主機地址 {{ $labels.instance }}) description: "主機內存已滿 當前內存小於百分之70\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"
Prometheus 查看觸發的告警信息
查看告警郵件
郵件中可以看到沒有標題為 (warning 測試內存)的告警郵件, 抑制生效。
靜默
靜音是在給定時間內簡單地將警報靜音的直接方法。靜音是基於匹配器配置的,就像路由樹一樣。檢查傳入警報是否與活動靜默的所有相等或正則表達式匹配器匹配。如果他們這樣做,則不會發送該警報的通知。
靜音是在 Alertmanager 的 Web 界面中配置的。
靜默可以在告警的時候要恢復服務器的時候避免重復告警, 或者說系統維護的時候也可以進行設置。