如何使用 Promql 获取不在另一个时间序列中的时间序列的数据点?

How to get the data points of a time series that are not in another time series using Promql?

例如,如果我有如下两个时间序列。

metric_1{id=1} 1
metric_1{id=2} 1
metric_1{id=3} 1
metric_2{id=1} 1
metric_2{id=3} 1

我想得到这个作为查询结果,因为 id=2 不在 metric_2

{id=2} 1

类似于这个问题 Comparison Query to Compare Two SQL Server Tables 但在 Promql 中。感谢您的帮助。

所以您基本上想要删除 metric_1 中所有具有标签值 id 的系列,这些系列也可以在系列 metric_2 中找到。在 SQL 中,这看起来像这样:

metric_1 left outer join metric_2 on id

首先在 Prometheus 中您可能会遇到 group_left。 (在这里 "Left joins in PromQL" 阅读更多相关信息。但这行不通。相反,我们使用 unless 运算符。

metric_1 unless on (id) metric_2