【问题标题】:How to snooze prometheus alert for specific time如何在特定时间打盹普罗米修斯警报
【发布时间】:2020-03-28 03:57:27
【问题描述】:

我在 Prometheus 内存警报方面遇到了一些问题。如果我备份 Gitlab,那么内存使用率会高达 95%。我想暂停特定时间的内存警报。

例如如果我在凌晨 2 点进行备份,那么我需要暂停 Prometheus 内存警报。有可能吗?

【问题讨论】:

    标签: prometheus prometheus-alertmanager


    【解决方案1】:

    正如 Marcelo 所说,没有办法安排静默,但如果定期进行备份(例如每天凌晨 2 点到凌晨 3 点),您可以将其包含在警报表达式中。

    - alert: OutOfMemory
      expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10 AND ON() absent(hour() >= 2 <= 3)
    

    如果您想要取消许多规则(或者如果您想要更复杂的抑制时间表),这可能会很快变得乏味。在这种情况下,您可以通过以下方式使用警报管理器的inhibition rules。

    第一步是在 Prometheus 中定义一个警报,在您希望抑制发生时触发:

    - alert: BackupHours
      expr: hour() >= 2 <= 3
      for: 1m
      labels:
        notification: none
      annotations:
        description: 'This alert fires during backup hours to inhibit others'
    

    记得在警报管理器中添加路由以避免通知此警报:

    routes:
      - match:
          notification: none
        receiver: do_nothing
    receivers:
    - name: do_nothing
    

    然后在这段时间内使用抑制规则使目标规则静音:

    inhibit_rules:
    - source_match:
        alertname: BackupHours
      target_match:
        # here can be any other selection of alert
        alertname: OutOfMemory
    

    请注意,它仅适用于 UTC 计算。如果您需要夏令时,则需要更多样板文件(以示例记录规则)。

    附带说明,如果您正在监控备份过程,您可能已经有一个指标表明备份正在进行中。如果是这样,您可以使用此指标来禁止其他警报,并且您不需要维护时间表。

    【讨论】:

    • 非常感谢。 this post 也可能有所帮助。
    【解决方案2】:

    不,不可能安排静音。

    针对您的情况的一些解决方法:

    1) 也许您可以更改您的 Prometheus 配置并增加“for”子句,以便在不触发警报的情况下有更多时间执行备份。

    2) 您可以使用 REST API 在备份开始/结束时创建/删除静音。

    查看有关此主题的更多信息here

    【讨论】:

      【解决方案3】:

      您可以比较历史上的条件,因此如果指标在过去两天的差异不超过 2 次,则不会弹出警报。

            - alert: CPULoadAlert
              # Condition for alerting
              expr: >-
                node_load5 / node_load5 offset 1d > 2 and
                node_load5 / node_load5 offset 2d > 2 and
                node_load5 > 1
              for: 5m
              # Annotation - additional informational labels to store more information
              annotations:
                summary: 'Instance {{ $labels.instance }} got an unusual high load on CPU'
                description: '{{ $labels.instance }} of job {{ $labels.job }} got CPU spike over 2x compared to previous 2 days.'
              # Labels - additional labels to be attached to the alert
              labels:
                severity: 'warning'
      

      【讨论】:

        猜你喜欢
        • 2022-11-02
        • 1970-01-01
        • 2019-02-28
        • 2021-07-20
        • 1970-01-01
        • 1970-01-01
        • 2022-01-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多