Flux query returns multiple values on aggregate window larger/equal then time period


when executing a flux query with an aggregate window larger then the time window over the API on InfluxDBv2 the result contains two values. Eg:

from(bucket: “pix”)
|> range(start: -5m)
|> filter(fn: (r) => r["_measurement"] == “cpu”)
|> filter(fn: (r) => r["_field"] == “usage_user”)
|> filter(fn: (r) => r[“cpu”] == “cpu-total”)
|> filter(fn: (r) => r[“host”] == “example/.org”)
|> aggregateWindow(every: 5m, fn: mean, createEmpty: false)



Setting the “every” param for aggregateWindow() to 1h returns only one value. Should not the query return only result ? If no, could this be accomplished by another function ?

Best regards,

In Flux when windowing is performed, the window boundaries will be aligned with the “every” duration, where windows are truncated if needed to respect the range of the query. Since the query range is 5 minutes ago to now, a window boundary falls into the middle of the range:

  • First window is 7:47:44.688 to 07:50:00
  • Second window is 7:50:00 to 07:52:44.688

If you really just want one value returned you can replace the last line of your query with

|> mean()

To get a mean over the entire query range.