InfluxDB: Flux - Aggregate the Sum over Time

Aus Wiki-WebPerfect
Version vom 13. August 2021, 12:22 Uhr von Admin (Diskussion | Beiträge)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
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 everything is as you expect, but if you use a selector function inside the aggregateWindow() the behaviour is a little bit strange.



//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