0

我正在使用 bosun 来监控一个指标,该指标在工作日的大部分时间应该是非零的,但可以在夜间为零/不可用。

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 点之间的时间为零或未知,它不会触发警报?我查看了文档,但我不确定如何进行与一天中的时间相关的查询。

4

1 回答 1

2

如果您真的对在特定时间是否满足警报条件不感兴趣,您可以在警报中引入附加条件并使用该epoch()功能。epoch()返回评估警报时的当前时间戳。然后将其添加到critorwarn条件。像这样的东西会起作用:

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 点之外进入严重或警告状态。如果您在多个警报中使用它,可能值得将其提取到宏中。

于 2019-12-11T14:06:13.210 回答