Filling gaps in timeline

Hi folks,

I’m pretty new to influxdb and trying to visualize data in grafana.
I have the following use case: I send the state of devices (managed by a server) to to the influxdb.
I use the Status History diagram in Grafana to visualize if a device was online or offline.

The problem I’m running into is: If the server does not send message (e.g. network issue) I assume the state offline for the the devices. But in the timeseries database there are no entries. So in grafana I get gaps.

Here is the query I’m using:

from(bucket: "demo")
 |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
 |> filter(fn: (r) => r["_measurement"] == "Devices")
 |> filter(fn: (r) => r["_field"] == "online")

Is there any possibility to fill this gaps with online=false ?

Hello @balu,
I’m not entirely sure I udnerstand your schema…
but it sounds like maybe you could do:

|> filter(fn: (r) => r["_field"] == "online" or  r["_field"] == "offline")
|> group() 

To visualize offline and online data as one line.

Otherwise you could do something like:

import "array"

array.from(rows: [{_time: 2020-01-01T00:00:00Z, _value: 1.0},{_time: 2020-01-02T00:00:00Z, _value: 2.0}])
  |> range(start: 2020-01-01T00:00:00Z, stop: 2020-01-03T00:00:00Z)
  |> aggregateWindow(every: 12h, fn: mean, createEmpty: true)
  |> fill(column: "_value", value: 0.9)  

Hope that helps

Hi @Anaisdg

yeah I think it’s a problem to store the online state as a boolean in the db.
Because I have to specifiy a fn in the aggrreateWindow function. And mean cannot act on booleans.
I switched to 0 and 1 for offline/online and now it works.

Thanks for your help :slight_smile: