我是Prometheus的新手,并在下面进行查询,以按百分比显示某个网站的平均正常运行时间,以进行SLA监控(例如,以Google为例)。
(avg_over_time(probe_success{instance="https://www.google.com/"}[$__range])) * 100
但是,有可能使计算忽略少于1分钟的任何停机时间吗?
答案 0 :(得分:1)
处理探针SLA的最佳方法是使用分位数功能,例如:
quantile_over_time(0.99, probe_success{instance="https://www.google.com/"}[$__range])
这不完全是这种查询,但是需要从基本的角度来思考。
也就是说,直接回答问题,避免1分钟的停机时间,这可以有所帮助:
avg_over_time(((avg_over_time(probe_success{instance="https://www.google.com"}[75s]) * 75) > bool(60))[$__range:]) * 100
现在让我们剖析此查询:
avg_over_time(probe_success{instance="https://www.google.com"}[75s])
在75秒内获得了平均值,因此我们可以尝试忽略100万次停机时间。将此称为UP_TIME_PERCENTAGE
。
UP_TIME_PERCENTAGE * 75
提供过去75秒钟的运行时间(以秒为单位)。将此称为UP_TIME_75S
。
UP_TIME_75S > bool(60)
提供了布尔1或0时间线,指示正常运行时间是否超过一分钟。将此称为IS_UP_MORE_THAN_1M
avg_over_time(IS_UP_MORE_THAN_1M[$__range:]) * 100
在给定的$__range
中导致正常运行时间超过1m的探测器所占的百分比。请注意:
。在子查询上应用..._over_time
方法很重要。