【问题标题】:Is there a way to multiply Prometheus metrics, but persist label when one of the metrics misses a label?有没有办法乘以普罗米修斯指标,但当其中一个指标遗漏标签时保留标签?
【发布时间】:2022-11-22 22:05:38
【问题描述】:

假设我有 2 个以下指标:

metric1{identifier="test", name="first"} 100
metric1{identifier="test", name="second"} 200

metric2{identifier="test", othername="third"} 2

我想编写一个 PromQL,它将第一个指标与特定标签(此处为identifier)上的第二个指标相乘,同时将所有其他标签保留在结果指标中(此处为nameothername),因此结果将是:

resultmetric{identifier="test", name="first", othername="third"} 200
resultmetric{identifier="test", name="second", othername="third"} 400

简单地乘以它是行不通的,因为这些指标有不同的标签集。

如果有办法,我怎样才能使这成为可能?

【问题讨论】:

    标签: prometheus promql


    【解决方案1】:

    尝试以下查询:

    metric1 * on(identifier) group_left(othername) metric2
    

    它会将每个metric1指标乘以具有相同identifier标签的metric2指标,同时将来自metric2othername标签添加到结果中。

    有关详细信息,请参阅these docs

    【讨论】:

      猜你喜欢
      • 2022-12-22
      • 2022-12-02
      • 1970-01-01
      • 2020-01-10
      • 2020-11-12
      • 2022-11-03
      • 2018-08-02
      • 2022-12-17
      • 1970-01-01
      相关资源
      最近更新 更多