【问题标题】:Check if any value is above treshold in a `sum by` query检查“sum by”查询中是否有任何值高于阈值
【发布时间】:2023-01-20 02:40:48
【问题描述】:

我有以下查询,它会导致每个端点和方法的错误率。如果任何值高于某个阈值,即 10%,是否有任何方法可以在 alertmanager 中创建警报(最好在警报正文中使用端点和方法名称)?

sum by (endpoint, method) (
    http_requests_received_total{code=~"5.."} / 
    http_requests_received_total
)

【问题讨论】:

    标签: prometheus promql prometheus-alertmanager alertmanager


    【解决方案1】:

    您可以从以下 PrometheusRule 数组中获得灵感:

        - alert: "APIErrorRateIsHigh"
          annotations:
            summary: "Error rate is high"
            description: 'Error rate is higher than 10% on {{ $labels.method }} - {{ $labels.endpoint }}
      VALUE = {{ $value }}
      LABELS = {{ $labels }}'
          expr: |-
            (
              sum by (endpoint, method)
              (
                rate(http_requests_received_total{code=~"5.."}[5m])
                  / 
                rate(http_requests_received_total[5m])
              )
            ) > 0.1
          for: 0m
          labels:
            severity: high
    

    我建议您在 prometheus 中测试查询,并将阈值设置为更容易触发测试的值,例如 0.0001。 然后你可以写你的警报规则。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      相关资源
      最近更新 更多