prometheus - 如何从 Prometheus 查询 API 延迟错误预算
问题描述
我有一个 Prometheus 直方图,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% 的时间失败?”。
解决方案
所以这里的秘密是我想将范围向量转换为范围向量。这在 Prometheus 中是不可能的,但解决方法是使用录制规则。
所以,需要做的是这样的:
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])
推荐阅读
- python - 正则表达式来标记句子python
- c - 在c中的文件中写入直到n的偶数整数,putw()函数错误
- flutter - 是否可以以编程方式控制 Flutter 中的选项卡(隐藏/可见)
- c - 如何在 C 编程中使用 Strtol 将包含逗号的整数与文本文件分开?
- r - 如何保存从ggplot中保存的颜色?
- python - 如何退出此程序中的循环
- reactjs - 渲染的反应格式——语法——意外标记
- javascript - React - 更新处于未知深度的 redux 状态的嵌套对象
- ionic-framework - Ionic 5 结果无法显示在控制台日志中
- c++ - 为什么在我的程序中出现分段错误?