I am using victoriametrics for recording devices from IOT Data. Every time a device sends a heartbeat to the server, I push into VM. Sometimes devices go offline. In my application, I want to query for the last seen time of the device during the day. I tried few options like
/query?
last_over_time(devicerecord_uptime{kd_id="807d3a73e0fd"}[24h])
and
/query?
devicerecord_uptime{kd_id="807d3a73e0fd"}[24h]
First one gives values but the timestamp is not the actual time of the event.
"value": [
1620822177, // This timestamp is time now, not the time of report
"19948"
]
The second one gives values but it gives all the values during 24H. Resulting into more bandwidth, less efficient, because I want to run a script for a lot of devices.
"values": [
... All day values
[
1620822770.508,
"20848"
],
[
1620823070.518,
"21148"
],
[1620823370.528,
"21448"
]
]
Is there a right way to get just the last seen time of the device?
That's the specific of /query endpoint - it executes an instant query at current timestamp and returns the closest result.
Have you tried "tlast_over_time(m[d]) - returns timestamp for the last sample for m over d time range" to get the timestamp? See more details here.