假设我有一个公制的 my_metric
并想根据标签计算出当前的指标和两天前的指标之间的差异。my_label
. 在PromQL中有没有一种方法可以不对标签值进行硬编码?
my_metric{exported_job="my_job",instance="dr01:9091",job="pushgateway",my_label="2020-05-01"} 10
my_metric{exported_job="my_job",instance="dr01:9091",job="pushgateway",my_label="2020-05-02"} 20
my_metric{exported_job="my_job",instance="dr01:9091",job="pushgateway",my_label="2020-05-03"} 60
假设我们在 2020-05-01
- 预期产出将是 60-10 = 50
.
换句话说--我需要一个查询,在SQL中是这样的。
SELECT m_2.value - m_1.value FROM my_metric m_1, my_metric m_2
WHERE diff_date('day', m_2.my_label, m_1.my_label) = 2
这将给你一个不同的时间,你调用的查询和度量值和2天前的差异。
my_metric{exported_job="my_job",instance="dr01:9091",job="pushgateway"}
- ignoring(my_label) my_metric{exported_job="my_job",instance="dr01:9091",job="pushgateway"} offset 2d
你可以在这里阅读更多关于偏移关键字的信息。https:/prometheus.iodocsprometheuslatestqueryingbasics#offset -modifier