Prometheus:根据标签值进行条件并添加其他结果作为信息
我有一个查询来执行
sum by(proxy, code) (rate(haproxy_server_http_responses_total{code=~"5xx|2xx",proxy="api_backend"}[10m]))
此查询的结果,
{code="2xx", proxy="api_backend"} value1
{code="5xx", proxy="api_backend"} value2
我想仅在 value2 > 时触发警报x 并添加有关 value2 的额外信息。(让 value2 因为它是无条件的)
我已尝试此代码,但它不起作用
sum by(proxy, code) (rate(haproxy_server_http_responses_total{code="5xx",proxy="api_backend"}[10m])) > x or sum by(proxy, code) (rate(haproxy_server_http_responses_total{code="2xx",proxy="api_backend"}[10m]))
i have a query to perform
sum by(proxy, code) (rate(haproxy_server_http_responses_total{code=~"5xx|2xx",proxy="api_backend"}[10m]))
the result of this query
{code="2xx", proxy="api_backend"} value1
{code="5xx", proxy="api_backend"} value2
i want to trigger the alert only when value2 > x and add extra information about value2.(let value2 as it is without condition)
I have trying this code but it is not working
sum by(proxy, code) (rate(haproxy_server_http_responses_total{code="5xx",proxy="api_backend"}[10m])) > x or sum by(proxy, code) (rate(haproxy_server_http_responses_total{code="2xx",proxy="api_backend"}[10m]))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下 PromQL 查询:
对于
5xx
响应率高于x
的代理,它应该返回2xx
响应率。它是如何运作的?
上面查询中的
by(proxy, code)
被替换为by(proxy)
。这是因为 Prometheus 在a
和b
端使用相同的标签集对时间序列执行a op b
查询。在原始查询中,标签集并不相同,因为它们的code
标签值不同。请参阅Prometheus 中二元运算符的匹配规则。or
运算符替换为and
运算符,并且rate(...{code="2xx"}
放入查询的前面,因为当b
处存在具有相同标签集的匹配时间序列时,a 和 b
返回a
。一个href="https://prometheus.io/docs/prometheus/latest/querying/operators/#ological-set-binary-operators" rel="nofollow noreferrer">这些文档了解有关或
和and
运算符。Try the following PromQL query:
It should return
2xx
response rates for proxies with5xx
response rates higher thanx
.How does it work?
The
by(proxy, code)
is substituted withby(proxy)
in the query above. This is because Prometheus performsa op b
query over time series with identical sets of labels ata
andb
sides. In the original query the set of labels weren't identical, because they differ bycode
label value. See matching rules for binary operators in Prometheus.The
or
operator is substituted withand
operator and therate(...{code="2xx"}
is put in the front of the query, sincea and b
returnsa
when there is a matching time series with the same set of labels atb
. See these docs for details aboutor
andand
operators.