问题描述
我有一个计数器类型的指标 varnish_main_client_req,我想设置一个警报,如果请求率在给定时间内下降/上升一定数量(例如Amount of请求在过去 2 分钟内有偏差!").
I have a metric varnish_main_client_req of type counter and I want to set up an alert that triggers if the rate of requests drops/raises by a certain amount in a given time (e.g. "Amount of requests deviated in the last 2 min!").
使用 deriv() 函数应该比比较相对值要好得多,但它只能与仪表一起使用.是否有可能转换一个不断增加的指标.与额定指标相反.量规?
Using the deriv() function should work much better than comparing relative values, but it can only be used with gauges. Is it possible to convert an ever increasing metric aka. counter to a rated metric aka. gauge?
查询:deriv(rate(varnish_main_client_req[2m])[5m])
期望:Prometheus 计算过去 2 分钟内客户端请求的速率,并返回过去 5 分钟内结果值的导数.
Expectation:Prometheus calculates the rate of client requests over the last 2 mins and returns a derivative of the resulting values over the last 5 mins.
实际结果:
"error":"解析 char 48 处的错误:必须在范围规范之前由一个度量选择器,但跟在 *promql.Call 后面"
记录规则 可能是一种选择,但感觉像是一种廉价的解决方法应该适用于查询:
Recording rules might be an option but it feels like a cheap workaround for something that should work with queries:
my_gauge_metric = rate(some_counter_metric[2m])
推荐答案
是的,您需要为此使用录制规则.
Yes, you need to use a recording rule for this.
Prometheus 计算过去 2 分钟内客户端请求的速率,并返回过去 5 分钟内结果值的导数.
问题就在这里 - Prometheus 应该在什么时间间隔合成这些数据?
Herein lies the problem - at what interval should Prometheus synthesise this data?
这篇关于从 Prometheus 查询中的返回值生成范围向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!