【问题标题】:Prometheus alert when pod is in Pending for more than 2 minutes当 Pod 处于 Pending 超过 2 分钟时,Prometheus 会发出警报
【发布时间】:2021-11-21 13:20:27
【问题描述】:

我们有一个系统可以在 Kubernetes 集群中启动短期 pod,并在它们开始运行时等待长达 2 分钟,否则,它会杀死它们。 我希望在使用 Prometheus 时收到警报。

我创建了以下警报表达式: min_over_time(sum by (namespace, pod) (kube_pod_status_phase{phase="Pending"})[2m:30s]) > 0 并面临许多误报通知。

据我了解,当 Prometheus 在 pod 生命周期的早期评估表达式时,它将始终返回 1,我需要添加一个附加条件来说明 Prometheus 类似“如果 pod 处于 Pending 状态2 分钟,超过 4 个数据点返回 1"。 有人知道如何扩展上面的表达式并添加附加条件吗?

【问题讨论】:

    标签: prometheus promql


    【解决方案1】:

    您可以使用可选的for 子句来执行此操作。 docs

    可选的 for 子句使 Prometheus 在第一次遇到新的表达式输出向量元素和将警报计数为触发该元素之间等待一段时间。在这种情况下,Prometheus 将在每次评估期间检查警报是否继续处于活动状态 10 分钟,然后再触发警报。处于活动状态但尚未触发的元素处于挂起状态。

    会是这样的:

      # Alert raises if it persists more than 2 minutes
      - alert: YourAlertName
        expr: sum by (namespace, pod) (kube_pod_status_phase{phase="Pending"})[2m:30s] > 1
        for: 2m
    

    【讨论】:

      猜你喜欢
      • 2020-09-22
      • 2020-10-16
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 2022-12-01
      • 1970-01-01
      • 2021-05-27
      相关资源
      最近更新 更多