InfluxDB: Flux - Aggregate the Sum over Time

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche

AggregateWindow() with sum() = unexpected behaviour

The Flux function aggregateWindow() is often used for timeseries data for example in a graph visualization.
Mostly you use the aggregation function mean() inside aggregateWindow() and then everything is as you expect, but if you use a selector function inside the aggregateWindow() the behaviour is a little bit strange (at least for me).



//define variables bucket = "${dynamicbucket}" fields = /Health_.+/ //Regex that matches both fields window = ${window}


customsum = (tables=<-, column="_value") =>

 tables
   |> mean()
   |> drop(columns: ["host", "_field"])
   |> sum(column)

from(bucket: bucket)

 |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
 |> filter(fn: (r) => 
   r._measurement == "hyperv_health" and
   r._field =~ fields
 )
 |> aggregateWindow(every: window, fn: customsum, createEmpty: false)
 |> fill(column: "_value", usePrevious: true)
 |> toInt() //round the result