prometheus - 如何使用普罗米修斯警报管理器抑制营业时间以外的警报?

标签 prometheus prometheus-alertmanager

我们的应用程序依赖于仅在工作时间内处于事件状态的数据源。我们在 Prometheus 中设置了警报,以在数据流干涸时通知我们。但是,我们不希望在工作时间以外收到“错误”警报。

我关注了 this post设置一个“假警报”,在非工作时间触发并应该禁止所有其他警报。

设置如下所示。在普罗米修斯中:

rules:

# This special alert will be used to inhibit all other alerts outside business hours
- alert: QuietHours
  expr: day_of_week() == 6 or day_of_week() == 0 or europe_amsterdam_hour >= 18 or europe_amsterdam_hour <= 7
  for: 1m
  labels:
    notification: page
    severity: critical
  annotations:
    description: 'This alert fires during quiet hours. It should be blackholed by Alertmanager.'
europe_amsterdam_hour函数被定义为规则,为了简洁起见,本示例中省略了它。

在警报管理器中:
routes:
# ensure to forward to blackhole receiver during quiet hours
- match:
    alertname: QuietHours
  receiver: blackhole

inhibit_rules:
- source_match:
    alertname: QuietHours
  target_match_re:
    alertname: '[^(QuietHours)]'

我验证了触发 QuietHours 警报的逻辑是否有效。它在工作时间后很好地触发并在工作时间解决。但是,禁止部分似乎不起作用,因为当 QuietHours 处于事件状态时,我仍然会收到其他警报。我找不到关于抑制配置的详细解释的好资源。

任何想法我做错了什么?

最佳答案

问题在于您的目标重新,语法不正确。没有必要排除QuietHoursinhibit_rule 中所述文档。

To prevent an alert from inhibiting itself, an alert that matches both the target and the source side of a rule cannot be inhibited by alerts for which the same is true (including itself).



正则表达式应该简单地匹配与您的数据源相关的警报。

添加标签来识别与禁止和使用它的源相关的警报比使用警报名称更容易。
inhibit_rules:
- source_match:
    alertname: QuietHours
  target_match:
    component: 'data_source'

这样,任何与源相关的新警报都将被禁止。

关于prometheus - 如何使用普罗米修斯警报管理器抑制营业时间以外的警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57305247/

相关文章:

go - 在 golang 中收集 Kubernetes 指标

influxdb - Prometheus 远程读取 influxdb

kubernetes - 如何使用 Prometheus Alert Manager 在 Kubernetes 中触发警报

azure - Helm 不接受 YAML 值

普罗米修斯 "negative"偏移量

go - 普罗米修斯计数器 : How to get current value with golang client?

python - Pushgateway - 值错误 : Incorrect label count

prometheus - 有状态集的 RollingUpdate 不会重新启动 Pod,并且更新的 ConfigMap 中的更改不会反射(reflect)出来

yaml - Loki 没有提醒 Alertmanager

prometheus-alertmanager - 警报管理器 : custom receiver or webhook receiver with custom POST payload?