【问题标题】:How to store the status of an expr in alert rules to use that in annotations?如何将 expr 的状态存储在警报规则中以在注释中使用它?
【发布时间】:2019-11-19 18:57:56
【问题描述】:

每当一个节点进入“未就绪”我的 Kubernetes 集群时,我都会为 prometheus 设置警报。每当发生这种情况时,我都会在 Slack 上收到通知。问题是我收到相同描述的通知“节点 xxxx 处于未就绪状态”,即使它重新启动也是如此。我正在尝试为节点的就绪状态使用一个变量,并在注释部分使用它。

我尝试使用“vars”和“when”将其分配给变量以在注释中使用它。

  - name: NodeNotReady
    rules:
    - alert: K8SNodeNotReadyAlert
      expr: kube_node_status_condition{condition="Ready",status="true"} == 0
      for: 3m
      vars:
      - ready_status: "Ready"
        when: kube_node_status_condition{condition="Ready",status="true"} == 1
      - ready_status: "Not Ready"
        when: kube_node_status_condition{condition="Ready",status="true"} == 0
      labels:
        severity: warning
      annotations:
        description: Node {{ $labels.node }} status is in {{ ready_status }}.
        summary: Node status {{ ready_status }} Alert!  

我想收到这些警报: 1.当节点为NotReady时:“Node prom-node status is in NotReady”。 2.当节点Ready时:“Node prom-node状态为NotReady。”

【问题讨论】:

    标签: annotations yaml alert prometheus rules


    【解决方案1】:

    所以你要找的东西是here。所以你应该在描述中得到这样的结果:

    Node {{ $labels.node }} status is in {{ if eq $value 1 }} Ready {{ else }} Not Ready {{ end }} status.
    

    在发出更多警报之前也值得阅读this

    【讨论】:

    • 对我不起作用,但是这样做了:节点 {{ $labels.node }} 状态是 {{ $value |人性化 |替换所有“1”“准备好”|替换所有“0”“未准备好”}}。
    • 但我仍然没有收到 Ready 和 NotReady 的不同松弛警报。显然 AlertManager 对两个 Slack 通知使用相同的注释。对此有何建议?
    • 如果我都重视您在 alertmanager 中的使用会更容易,因为上面的模板应该可以工作。你得到相同的注释,但这两个中的哪一个?给我更多细节(尽可能多)。
    • 感谢@Armatorix。我为节点向上和向下添加了多个注释。并使用“if conditions”在警报管理器中调用它。
    猜你喜欢
    • 2020-06-10
    • 1970-01-01
    • 2018-07-03
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多