'Grafana and Influx time since last measurement

I want to show time since last measurement from influxDB in grafana. I can't find solution to do that in grafana (because since grafana 7 "Singlestat panel" is deprehended). I've also tried to calculate difference between last measurement and "now()" in influx, just like below:

from(bucket: "bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "measurement")
  |> filter(fn: (r) => r["_field"] == "field")
  |> group()
  |> first()
  |> map(fn: (r) => ({ time: uint(v: now()) - uint(v: r._time)})) 

Unfortunately this is also wrong. Result of that calculation is something like 2112-3-21 18:23:33 and what I'm expecting is 20 min for example.

Do you know any solution?



Solution 1:[1]

I was trying to do the same thing and found the problem. When you convert time to uint this return nanosecond epoch timestamp. You must divide the result you obtained by 10E9 to obtain the time in seconds

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luca Kiebel