在promQL中嵌套查询

时间:2020-08-30 18:23:49

标签: prometheus promql

我正在寻找度量标准'prom_metric2'的输出,其中输入标签为'label2',其值必须取自度量标准'prom_metric1'。

即用于后续输入查询:

prom_metric1{label1="A"}

输出时间序列是:

prom_metric1{label1="A",label2="B",label3="C"}
prom_metric1{label1="A",label2="D",label3="E"}

现在,以下指标应采用上述时间序列中的label2的所有值,然后显示输出。

prom_metric2{label2="LABEL_FROM_PROM_METRIC1 i.e. B and D"}

它等效于以下SQL查询:

Select * from prom_metric2 where label2 IN (Select label2 from prom_metric1 where label1='A')

在promQL中有可能吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

以下解决方案工作正常:

prom_metric2 {some_label="value"} and on (label2 ) prom_metric1 {label1='A'}

参考: https://www.robustperception.io/exposing-the-software-version-to-prometheus

https://prometheus.io/docs/prometheus/latest/querying/operators/#many-to-one-and-one-to-many-vector-matches