[英]How to snooze prometheus alert for specific time
我遇到了 Prometheus 內存警報的一些問題。 如果我備份 Gitlab,那么內存使用率會高達 95%。 我想暫停特定時間的內存警報。
例如,如果我在凌晨 2 點進行備份,那么我需要暫停 Prometheus 內存警報。 可能嗎?
正如 Marcelo 所說,沒有辦法安排靜默,但如果定期進行備份(例如從凌晨 2 點到凌晨 3 點的每晚),您可以將其包含在警報表達式中。
- alert: OutOfMemory
expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10 AND ON() absent(hour() >= 2 <= 3)
如果您想使許多規則保持沉默(或者如果您想要更復雜的抑制時間表),這可能會很快變得乏味。 在這種情況下,您可以通過以下方式使用警報管理器的抑制規則。
第一步是在 Prometheus 中定義一個警報,在您希望抑制發生時觸發:
- alert: BackupHours
expr: hour() >= 2 <= 3
for: 1m
labels:
notification: none
annotations:
description: 'This alert fires during backup hours to inhibit others'
請記住在警報管理器中添加路由以避免通知此警報:
routes:
- match:
notification: none
receiver: do_nothing
receivers:
- name: do_nothing
然后在這段時間內使用禁止規則使目標規則靜音:
inhibit_rules:
- source_match:
alertname: BackupHours
target_match:
# here can be any other selection of alert
alertname: OutOfMemory
請注意,它僅適用於 UTC 計算。 如果您需要 DST,則需要更多樣板文件(例如記錄規則)。
附帶說明一下,如果您正在監控備份過程,您可能已經有一個指標表明備份正在進行中。 如果是這樣,您可以使用此指標來禁止其他警報,並且您不需要維護時間表。
不,不可能有預定的沉默。
針對您的情況的一些解決方法:
1)也許您可以更改您的 Prometheus 配置並增加“for”子句,以便在不觸發警報的情況下有更多時間執行備份。
2) 您可以使用 REST API 在備份的開始/結束時創建/刪除靜音。
在此處查看有關此主題的更多信息。
您可以比較歷史記錄中的條件,因此如果此時指標在過去兩天內的差異不超過 2 次,則不會彈出警報。
- alert: CPULoadAlert
# Condition for alerting
expr: >-
node_load5 / node_load5 offset 1d > 2 and
node_load5 / node_load5 offset 2d > 2 and
node_load5 > 1
for: 5m
# Annotation - additional informational labels to store more information
annotations:
summary: 'Instance {{ $labels.instance }} got an unusual high load on CPU'
description: '{{ $labels.instance }} of job {{ $labels.job }} got CPU spike over 2x compared to previous 2 days.'
# Labels - additional labels to be attached to the alert
labels:
severity: 'warning'
我想對@Michael Doubez 發表評論,但我還沒有足夠的分數。
我正在編寫一個導出器,它表示維護窗口處於活動狀態,然后該指標可用於使用禁止規則來禁止警報。 您可以使用良好的老式 cron 表達式定義多個維護窗口。 見https://github.com/jzandbergen/maintenance-exporter
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.