我们的应用程序依赖于仅在工作时间内活跃的数据源。我们在普罗米修斯中设置了警报,以便在溪流干涸时通知我们。但是,我们不希望在工作时间之外收到“错误”警报。
我跟着这个帖子 https://medium.com/@tom.fawcett/time-of-day-based-notifications-with-prometheus-and-alertmanager-1bf7a23b7695设置一个“假警报”,在工作时间之外触发,并应该抑制所有其他警报。
设置如下所示。在普罗米修斯中:
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.'
The 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 处于活动状态时我仍然会收到其他警报。我找不到对抑制配置有详细解释的好资源。
有什么想法我做错了吗?
问题在于您的目标 re,语法不正确。没有必要排除QuietHours
如中所解释的抑制规则 https://prometheus.io/docs/alerting/configuration/#inhibit_rule文档。
为了防止警报抑制自身,与两者都匹配的警报
规则的目标端和源端不能被警报抑制
对于这也是如此(包括它本身)。
正则表达式应该简单地匹配与您的数据源相关的警报。
添加标签来识别与源相关的警报以抑制和使用它比使用警报名称更容易。
inhibit_rules:
- source_match:
alertname: QuietHours
target_match:
component: 'data_source'
这样,任何与源相关的新警报都将被禁止。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)