2

I have points spread out every 5 min, and when the value is 0 the point is just omitted. I'd like to fill the omitted data with empty values.

I see with InfluxQL I could do:

group by time(5m) fill(0)

But I am using InfluxDB 2. I have tried this query:

      from(bucket:"%v")
         |> range(start: %d) 
         |> filter(fn: (r) => r._measurement == "volume" and r.id == "%v")
         |> window(every: 5m, period: 5m, createEmpty: true)
         |> fill(value: 0)

But it does not appear to be working.

Any help is appreciated.

aa bb
  • 247
  • 3
  • 9

3 Answers3

2

It turns out this is a bug in InfluxDB related to https://github.com/influxdata/influxdb/issues/21857

Apparently the window function does not work either.

aa bb
  • 247
  • 3
  • 9
1

[InfluxDB2] fill() sparse data with 0 points

had the same problem

Influxdb connects series without 0 ,here a cpu graph with missing timeframes Influxdb connects series without 0 ,here a cpu graph with missing timeframes

  • fill() only works on integers,
  • non-existing datapoints can't be if-catched by value (...)
  • aggregateWindow() finally helped

Solution: InfluxDB2 null as zero (float())

from(bucket: "sys")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "docker_cpu_percent" )
//  |> window(every: 5m, period: 5m, createEmpty: true)
  |> aggregateWindow(every: 5m, fn: mean, createEmpty: true)
  |> map(fn: (r) => ({
      r with
      _value: if exists r._value then float(v: r._value) * 1.0  else 0.0
    })
  )

Proper resonse from influx with null as 0 float() when using aggregateWindow()

if you need your lines connected with larger every/period values ( e.g. 8h ), you might try to add fill() like this

  |> aggregateWindow(every: 4h, fn: distinct, createEmpty: true)
  |> fill(usePrevious: true)

Resources

You might refer to

Bencho Naut
  • 348
  • 1
  • 6
0

The fill() function only replaces nulls in the data and not missing data points based on time. At the moment there's no function available to this time, although one has been requested.

What I've done over time periods where I need to fill in missing data is to generate a time series (with zero values) and join this with the time series with missing data.

FractalDoctor
  • 2,496
  • 23
  • 32
  • 3
    I thought that `window(every: 5m, period: 5m, createEmpty: true)` would create null values for every 5 minute interval though? – aa bb Jul 10 '21 at 04:07