普罗米修斯警报管理器中基于时间的警报

问题描述 投票:0回答:2

我想在 Prometheus Alertmanager 中设置一个警报,该警报必须在给定时间之间触发 例如:09:15 至 15:30 之间检查状况

prometheus prometheus-alertmanager
2个回答
4
投票

Prometheus 中的警报会定期评估,您无法真正为其设置时间表。

我认为可以通过一些 PromQL Kong Fu 来实现:

scalar(clamp(hour() > 9 and hour() < 15, 1, 1)) * <alert_promql>

hour() > 9 and hour() < 15
根据一天中的小时定义时间范围(您也可以添加分钟)

clamp(..., 1, 1)
确保该值为 1 而不是其他值

*
- 这就是奇迹发生的地方。 如果我们从前一个函数中得到任何值,它将是 1,因此乘以 1 对第二个表达式没有影响。 否则,第一个表达式上没有级数,因此乘法无论如何都不会返回结果。


0
投票

您可以使用的另一个选项是警报管理器配置中的active_time_intervals

# Times when the route should be active. These must match the name of a # time interval defined in the time_intervals section. An empty value # means that the route is always active. # Additionally, the root node cannot have any active times. # The route will send notifications only when active, but otherwise # acts normally (including ending the route-matching process # if the `continue` option is not set). active_time_intervals: [ - <string> ...]
因此您的配置示例如下

global: ... route: group_by: ['...'] receiver: 'black-hole-receiver' routes: - matchers: - env=dev continue: true receiver: 'black-hole-receiver' active_time_intervals: - workHours time_intervals: - name: workHours time_intervals: - times: - start_time: 09:00 end_time: 17:00 weekdays: ['monday:friday'] receivers: - name: 'black-hole-receiver'
    
© www.soinside.com 2019 - 2024. All rights reserved.