【问题标题】:Prometheus/PromQL/Grafana: Substraction when the right side range vector is potentially non-existentPrometheus/PromQL/Grafana:当右侧范围向量可能不存在时的减法
【发布时间】:2021-08-28 13:43:24
【问题描述】:

我有两个计数器指标:always_existssometimes_exists

我想从减法 always_exists - sometimes_exists 接收结果向量,即使度量标准 sometimes_exists 不存在(即查询不返回任何内容)。在这种情况下,我希望结果等于always_exists - 0。这可能吗?

【问题讨论】:

    标签: prometheus grafana promql


    【解决方案1】:

    尝试以下查询:

    (always_exists - sometimes_exists) or (always_exists unless sometimes_exists)
    

    它使用orunless 运算符。在https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators查看有关这些运算符的更多详细信息

    附:查询可以简化为VictoriaMetrics 中的sum(always_exists, -sometimes_exists),因为MetricsQL 支持聚合函数中的多个参数,例如sum。 (我是 VictoriaMetrics 的核心开发者)

    【讨论】:

    • 非常感谢。我不知道我在不弄清楚这种运算符组合的情况下滚动过文档中的这一部分的频率。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 2017-12-13
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 2021-01-20
    相关资源
    最近更新 更多