Change time duration/truncate ns

  • What Grafana version and what operating system are you using?

Grafana 13 + Influxdb v2 + Debian

  • What are you trying to achieve?

I have calculated a time duration via flux. This duration has ms, us and ns. I want to truncate those or transform this field so that only days, hours and minutes are shown.

This is how it looks:

and this is what i want (or something similar)

my query:

from(bucket: "firewall")
  |> range(start: -120d)
  |> filter(fn: (r) => r["host"] == "firewall.homelab.lan")
  |> filter(fn: (r) => r["_measurement"] == "interface")
  |> filter(fn: (r) => r["friendlyname"] == "WAN")
  |> filter(fn: (r) => r["_value"] == 0)
  |> last()
  |> map(fn: (r) => ({ r with current_timestamp: uint(v: now())}))
|> map(fn: (r) => ({ r with event_timestamp: uint(v: r._time) }))
|> map(fn: (r) => ({ r with time_since_event: string(v: duration(v: r.current_timestamp - r.event_timestamp))}))
|> map(fn: (r) => ({_time_since_event:r.time_since_event}))

Cast result as int, not a string (+calculate diff in ms), use Unit Duration (ms) and set suitable precision.
Example (not a copy&paste solution for your issue):

That did not work. I am getting a value of more than 900years.

As I said this is not a copy&paste solution for your issue, but concept what you need to do.

How did you calculate duration in ms in the query?