简体   繁体   English

Prometheus 查询:在 Grafana 中加入 2 个指标

[英]Prometheus Query : Joining 2 metrics in Grafana

Metric 1: custom_closed_orders_total{store="5222"} results in:指标 1: custom_closed_orders_total{store="5222"}结果:

host1,host2,host3,host4

Metric 2: host_offline:health_check_container:sum{store="5222"} results in:指标 2: host_offline:health_check_container:sum{store="5222"}结果:

host1,host2,host3,host4,host5,host6 

I would like to have a query which shows the following result:我想要一个显示以下结果的查询:

host5, host6

The best that I could do is:我能做的最好的是:

(count(custom_closed_orders_total{store="5222"} offset 7d) by (host)) 
- on(lane) group_left(host) 
count(host_offline:health_check_container:sum{store="5222"} offset 7d) by (host)

Can someone please help me how to get the expected results by modifying the above query?有人可以帮助我如何通过修改上述查询来获得预期结果吗?

If I understood you correctly you are looking for how to get the values of one metric that is not present on the second metric (or vice-versa).如果我对您的理解正确,您正在寻找如何获取第二个指标中不存在的一个指标的值(反之亦然)。 If so, you can use the unless (complement) operator as the docs says :如果是这样,您可以按照文档所述使用unless (补码)运算符:

vector1 unless vector2 results in a vector consisting of the elements of vector1 for which there are no elements in vector2 with exactly matching label sets. vector1 除非 vector2 产生一个由 vector1 的元素组成的向量,而 vector2 中没有元素与 label 集合完全匹配。 All matching elements in both vectors are dropped.两个向量中的所有匹配元素都被丢弃。

You can do something like this:你可以这样做:

host_offline:health_check_container:sum{store="5222"} 
unless 
custom_closed_orders_total{store="5222"}

Be aware that the order of the metrics used before or after the unless function matters.请注意,在unless function 之前或之后使用的指标顺序很重要。 As a demo example check this .作为演示示例检查这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM