prometheus - Prometheus/PromQL/Grafana:右侧范围向量可能不存在时的减法
问题描述
我有两个计数器指标:always_exists
和sometimes_exists
.
我想从减法接收一个结果向量always_exists - sometimes_exists
,即使指标sometimes_exists
不存在(即查询不返回任何内容)。在这种情况下,我希望结果等于always_exists - 0
。这可能吗?
解决方案
尝试以下查询:
(always_exists - sometimes_exists) or (always_exists unless sometimes_exists)
它使用or
和unless
运算符。在https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators查看有关这些运算符的更多详细信息
PS 查询可以简化为sum(always_exists, -sometimes_exists)
VictoriaMetrics ,因为MetricsQL支持聚合函数中的多个参数,例如sum
. (我是 VictoriaMetrics 的核心开发者)
推荐阅读
- c# - 无论方向如何,如何逐渐向对象添加更多力以提高其速度?
- scala - 在 Flink 中处理的数据不保存在 Cassandra 数据库中
- r - 如何在 R Shiny 中准备分段仪表板?
- documentation - 在新项目中理解业务逻辑的最快方法
- java - 如何构建可执行的 JavaFx Jar 文件
- python - 如何将压缩文件夹中的 CSV 文件从 URL 加载到 Pandas DataFrame
- reporting-services - SSRS 多值参数 - 当全选时,返回零行
- python - 如何改进我的队列系统 - Discord.py
- java - 使用 spring mvc 在资源文件中下载 .xlsx 文件
- javascript - 如何使用角度离子中的json数据根据其他下拉列表中的选定状态在一个下拉列表中显示城市?