如何使用 Prometheus 计算指标高于特定值的时间?

How to calculate time a metric is above a specific value with Prometheus?

我是 Prometheus 的初学者,正在寻找一些查询帮助(看起来很基础,但我正在努力寻找正确的语法)。

我有一个称为“速度”的指标,return 探测器的速度(在 km/h 中)。我想计算 driver 在过去的 50km/h(限速)速度上行驶了多少时间 - 比方说 - 60 分钟。也可能在特定速度范围之间(例如:40 到 50)。

我附上了一个 Grafana 图表来说明它 - 我想计算 driver 在这个区域花费了多少时间。

谢谢

尝试以下查询:

avg_over_time((speed > bool 50)[1h:]) * 60

Here you'll find more details about this query which uses the bool modifier and the subquery支持。