【问题标题】:Prometheus Query : Joining 2 metrics in GrafanaPrometheus 查询:在 Grafana 中加入 2 个指标
【发布时间】:2021-08-12 06:51:53
【问题描述】:

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

host1,host2,host3,host4

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

host1,host2,host3,host4,host5,host6 

我想要一个显示以下结果的查询:

host5, host6

我能做的最好的就是:

(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)

有人可以通过修改上述查询来帮助我如何获得预期的结果吗?

【问题讨论】:

  • 有人能帮我解决这个问题吗

标签: prometheus


【解决方案1】:

如果我对您的理解正确,您正在寻找如何获取第二个指标上不存在的一个指标的值(反之亦然)。如果是这样,您可以使用unless(补码)运算符as the docs says

vector1 除非 vector2 产生一个由 vector1 的元素组成的向量,对于这些元素,vector2 中没有与标签集完全匹配的元素。两个向量中的所有匹配元素都将被删除。

你可以这样做:

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

请注意,unless 函数之前或之后使用的指标的顺序很重要。作为演示示例check this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 2019-08-28
    • 2020-06-15
    • 2020-08-03
    • 2018-12-24
    • 1970-01-01
    • 2020-02-25
    • 2021-03-20
    相关资源
    最近更新 更多