prometheus - Prometheus - 基于标签算法的条件
问题描述
假设我有一个指标my_metric
,并且想根据 label 计算当前指标与两天前的指标之间的差异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
您可以在此处阅读有关 offset 关键字的更多信息: https ://prometheus.io/docs/prometheus/latest/querying/basics/#offset-modifier
推荐阅读
- c# - 如何修复 Visual Studio 将 C# Unity 脚本视为杂项,因此无法自动完成?
- sql - 为什么使用子查询时此查询会变慢
- git - Git Subtree 拉取并自动提交合并
- python - Python中的枚举不转换为数字
- reactjs - 基于设备 Reactjs 的不同 slick-slider 设置参数
- python - Python 中的轻量级 OneDrive 同步(/本地缓存)
- web-scraping - 查找类的子类并返回元素列表
- javascript - 如何获取chart.js图表的json文件数据
- xcode - Xcode 无法提交文件:“与服务的通信中断”
- java - 通过 swagger UI 请求返回状态 200 和 x-frame-options: DENY of KeycloakWebSecurityConfigurerAdapter 保护 API