代码之家  ›  专栏  ›  技术社区  ›  Ztyx

如何从Prometheus查询API延迟错误预算

  •  1
  • Ztyx  · 技术社区  · 6 年前

    我有普罗米修斯柱状图, api_response_duration_seconds ,其中一个slo定义为

    histogram_quantile(0.95, sum(increase(api_response_duration_seconds_bucket[1m])) by (le)) <= 0.5
    

    对于我来说,有没有一个简单的方法来查询这个查询在过去28天(以百分比表示)中失败了多少? 也就是说,我希望能够回答“这个查询在过去28天中失败了超过0.1%的时间吗?”.

    1 回复  |  直到 6 年前
        1
  •  2
  •   Ztyx    6 年前

    所以这里的秘密是,我想把一个范围向量转换成一个范围向量。这个 isn't possible in Prometheus, but the workaround is to use a recording rule .

    所以,需要做的是:

    groups:
      - name: SLOs
      - rules:
        - record: slo:api_response_duration_seconds:failing
          expr: histogram_quantile(0.95, sum(increase(api_response_duration_seconds_bucket[1m])) by (le)) > 0.5
        - record: slo:api_response_duration_seconds:all
          expr: histogram_quantile(0.95, sum(increase(api_response_duration_seconds_bucket[1m])) by (le))
    

    然后查询错误预算为

    count_over_time(slo:api_response_duration_seconds:failing[28d])
    /
    count_over_time(slo:api_response_duration_seconds:all[28d])