【问题标题】:Get last seen value and time of a metric in Victoriametrics在 Victoriametrics 中获取指标的最后看到值和时间
【发布时间】:2021-05-12 12:51:52
【问题描述】:

我正在使用 victoriametrics 从 IOT Data 记录设备。每次设备向服务器发送心跳时,我都会推送到 VM。有时设备会离线。 在我的应用程序中,我想查询一天中设备的最后一次看到时间。 我尝试了几个选项,例如

/query?
last_over_time(devicerecord_uptime{kd_id="807d3a73e0fd"}[24h])

/query?
devicerecord_uptime{kd_id="807d3a73e0fd"}[24h]

第一个给出值,但时间戳不是事件的实际时间。

"value": [
                    1620822177, // This timestamp is time now, not the time of report
                    "19948"
         ]

第二个给出值,但它给出了 24H 期间的所有值。导致带宽增加,效率降低,因为我想为很多设备运行脚本。

"values": [
... All day values
    [
        1620822770.508,
        "20848"
    ],
    [
        1620823070.518,
        "21148"
    ],

    [1620823370.528,
        "21448"
    ]
]

是否有正确的方法来获取设备的最后一次看到时间?

【问题讨论】:

    标签: prometheus promql victoriametrics


    【解决方案1】:

    第一个给出值,但时间戳不是事件的实际时间。

    这是 /query 端点的特殊之处 - 它在当前时间戳执行即时查询并返回最接近的结果。

    您是否尝试过“tlast_over_time(m[d]) - 返回 d 时间范围内 m 的最后一个样本的时间戳”来获取时间戳?查看更多详情here

    【讨论】:

      猜你喜欢
      • 2022-11-24
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      相关资源
      最近更新 更多