You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PromQL计算blackbox exporter请求耗时占比遇错,求正确查询方法

解决Blackbox Exporter响应时间SLI统计问题

错误原因分析

你之前的查询probe_duration_seconds{}[5h] < 0.3报错,是因为probe_duration_seconds{}[5h]是范围向量(包含指定时间范围内的所有样本序列),而PromQL的二元比较要求只能是「标量+瞬时向量」的组合,范围向量不能直接参与这类比较。

正确PromQL查询语句

下面是针对你需求的具体查询,可根据实际标签(比如job、endpoint)调整过滤条件:

1. 统计过去5小时内,耗时超过300ms的GET请求数量

count_over_time(probe_duration_seconds{method="GET"} > 0.3 [5h]) by (instance)

2. 统计过去5小时内,耗时超过1s的GET请求数量

count_over_time(probe_duration_seconds{method="GET"} > 1 [5h]) by (instance)

3. 计算过去5小时内,耗时低于300ms的GET请求占比(百分比)

(
  count_over_time(probe_duration_seconds{method="GET"} <= 0.3 [5h]) by (instance)
  /
  count_over_time(probe_duration_seconds{method="GET"}[5h]) by (instance)
) * 100

关键逻辑说明

  • count_over_time():用于统计指定时间范围内,符合条件的样本总数(每个探测会生成一个probe_duration_seconds样本,所以样本数就是请求次数)
  • 先通过> 0.3/<= 0.3过滤出符合响应时间条件的瞬时样本,再用count_over_time()统计这段时间内的总次数
  • by (instance):按服务实例分组统计,可替换为你需要的维度(比如job、endpoint)

内容的提问来源于stack exchange,提问作者AlexW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 07:50:14