【问题标题】:Count how many times an event occurred or a metric was reported using PromQL使用 PromQL 计算事件发生或指标报告的次数
【发布时间】:2020-11-19 18:01:11
【问题描述】:

我使用 Victoria Metrics 来跟踪 IOT 设备。每当设备连接/断开连接时,我都会在 Victoria Metrics 中插入一个指标。我的指标名称是 devcon_s。 我可以使用这个查询数据 - devcon_s{device_id="something"}

但我想知道一天中设备断开连接的频率。我尝试这样的查询 - sum_over_time(count_values without(kd_id) ("value", devcon_s{kd_id="something"} == 0)[1d:])

count_over_time((devcon_s{kd_id="something"} == 0)[1d:])

步长等于 1d 或 1h。但它并没有给我报告事件的实际计数,而是其他对我没有意义的东西。 难道我做错了什么 ?还是无法计算 promQL 中的实际值数

【问题讨论】:

    标签: prometheus promql victoriametrics metricsql


    【解决方案1】:

    MetricsQL 提供count_le_over_time(m[d], le) 函数,该函数返回与m 匹配的每个时间序列在[d] 时间范围内值小于或等于le 的原始数据点的数量。

    以下查询应返回最后一天值为

    count_le_over_time(devcon_s{k_id="something"}[1d])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-28
      • 2016-12-06
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多