使用 Bosun,我怎样才能在一天中的某些时间不触发警报?
Using Bosun, how can I make an alert not trigger for certain times of day?
我正在使用 bosun 来监控一个指标,该指标在工作日的大部分时间都应该是非零的,但在夜间 zero/unavailable 是可以的。
alert myalert {
$notes = `This alert triggers when cw- orders haven't been received recently.`
template = noweborders
unknownIsNormal = 0
$metricLabel = Orders
$metric = q("max:1d-max:rate{counter,,1}:metricname{filtercategory=cw-,host=*}", "2w", "")
$graph = q("max:1m-max:rate{counter,,1}:metricname{filtercategory=literal_or(cw-),host=wildcard(*)}", "1d", "")
$uptimeStoppedWarn = since($metric) > d("2h")
$uptimeStoppedCrit = since($metric) > d("4h")
$lastOrder = ungroup(since($metric)) / 60 / 60
warn = $uptimeStoppedWarn
crit = $uptimeStoppedCrit
warnNotification = georgeemail
critNotification = georgeemail
}
我如何最好地调整此警报,以便如果指标在晚上 8 点和早上 8 点之间为零或未知,则不会触发警报?我已经查看了文档,但我不确定如何进行与一天中的时间相关的查询。
如果您真的对在特定时间是否满足警报条件不感兴趣,可以在警报中引入附加条件并使用 epoch()
功能。 epoch()
returns 评估警报时的当前时间戳。然后将其添加到 crit
或 warn
条件。这样的事情会起作用:
alert myalert {
$notes = `This alert triggers when cw- orders haven't been received recently.`
(...)
$eight_pm = 20*60*60
$eight_am = 8*60*60
$seconds_today = epoch() % 86400
$is_before_8am = $seconds_today < $eight_am
$is_after_8pm = $eight_pm <= $seconds_today
$should_alert = !$is_before_8am && !$is_after_8pm
warn = $uptimeStoppedWarn && $should_alert
crit = $uptimeStoppedCrit && $should_alert
warnNotification = georgeemail
critNotification = georgeemail
}
这将防止警报在上午 8 点到晚上 8 点之外进入严重或警告状态。如果您在多个警报中使用它,可能值得将其提取到宏中。
我正在使用 bosun 来监控一个指标,该指标在工作日的大部分时间都应该是非零的,但在夜间 zero/unavailable 是可以的。
alert myalert {
$notes = `This alert triggers when cw- orders haven't been received recently.`
template = noweborders
unknownIsNormal = 0
$metricLabel = Orders
$metric = q("max:1d-max:rate{counter,,1}:metricname{filtercategory=cw-,host=*}", "2w", "")
$graph = q("max:1m-max:rate{counter,,1}:metricname{filtercategory=literal_or(cw-),host=wildcard(*)}", "1d", "")
$uptimeStoppedWarn = since($metric) > d("2h")
$uptimeStoppedCrit = since($metric) > d("4h")
$lastOrder = ungroup(since($metric)) / 60 / 60
warn = $uptimeStoppedWarn
crit = $uptimeStoppedCrit
warnNotification = georgeemail
critNotification = georgeemail
}
我如何最好地调整此警报,以便如果指标在晚上 8 点和早上 8 点之间为零或未知,则不会触发警报?我已经查看了文档,但我不确定如何进行与一天中的时间相关的查询。
如果您真的对在特定时间是否满足警报条件不感兴趣,可以在警报中引入附加条件并使用 epoch()
功能。 epoch()
returns 评估警报时的当前时间戳。然后将其添加到 crit
或 warn
条件。这样的事情会起作用:
alert myalert {
$notes = `This alert triggers when cw- orders haven't been received recently.`
(...)
$eight_pm = 20*60*60
$eight_am = 8*60*60
$seconds_today = epoch() % 86400
$is_before_8am = $seconds_today < $eight_am
$is_after_8pm = $eight_pm <= $seconds_today
$should_alert = !$is_before_8am && !$is_after_8pm
warn = $uptimeStoppedWarn && $should_alert
crit = $uptimeStoppedCrit && $should_alert
warnNotification = georgeemail
critNotification = georgeemail
}
这将防止警报在上午 8 点到晚上 8 点之外进入严重或警告状态。如果您在多个警报中使用它,可能值得将其提取到宏中。