aggregateWindow() function

Warning! This page documents an earlier version of Flux, which is no longer actively developed. Flux v0.65 is the most recent stable version of Flux.

The aggregateWindow() function applies an aggregate or selector function (any function with a column parameter) to fixed windows of time.

Function type: Aggregate

aggregateWindow(
  every: 1m,
  fn: mean,
  column: "_value",
  timeColumn: "_stop",
  timeDst: "_time",
  createEmpty: true
)

As data is windowed into separate tables and processed, the _time column is dropped from each group key. This function copies the timestamp from a remaining column into the _time column. View the function definition.

Parameters

Make sure fn parameter names match each specified parameter. To learn why, see Match parameter names.

every

The duration of windows.

Data type: Duration

fn

The aggregate function used in the operation.

Data type: Function

Only aggregate and selector functions with a column parameter (singular) work with aggregateWindow().

column

Columns on which to operate. Defaults to "_value".

Data type: String

timeColumn

The time column from which time is copied for the aggregate record. Defaults to "_stop".

Data type: String

timeDst

The “time destination” column to which time is copied for the aggregate record. Defaults to "_time".

Data type: String

createEmpty

For windows without data, this will create an empty window and fill it with a null aggregate value. Defaults to true.

Data type: Boolean

Examples

Using an aggregate function with default parameters
from(bucket: "telegraf/autogen")
  |> range(start: 1h)
  |> filter(fn: (r) =>
    r._measurement == "mem" and
    r._field == "used_percent")
  |> aggregateWindow(
    every: 5m,
    fn: mean
  )
Specify parameters of the aggregate function

To use functions that don’t provide defaults for required parameters with aggregateWindow(), define an anonymous function with column and tables parameters that pipe-forward tables into the aggregate or selector function with all required parameters defined:

from(bucket: "telegraf/autogen")
  |> range(start: 1h)
  |> filter(fn: (r) =>
    r._measurement == "mem" and
    r._field == "used_percent")
  |> aggregateWindow(
    every: 5m,
    fn: (column, tables=<-) => tables |> quantile(q: 0.99, column:column)
  )

Function definition

aggregateWindow = (every, fn, columns=["_value"], timeColumn="_stop", timeDst="_time", tables=<-) =>
	tables
		|> window(every:every)
		|> fn(column:column)
		|> duplicate(column:timeColumn, as:timeDst)
		|> window(every:inf, timeColumn:timeDst)

InfluxQL aggregate functions
GROUP BY time()