aggregateWindow() function

The aggregateWindow() function applies an aggregate function to fixed windows of time.

Function type: Aggregate

aggregateWindow(
  every: 1m,
  fn: mean,
  columns: ["_value"],
  timeColumn: "_stop",
  timeDst: "_time"
)

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

Parameters

every

The duration of windows.

Data type: Duration

fn

The aggregate function used in the operation.

Data type: Function

columns

List of columns on which to operate. Defaults to ["_value"].

Data type: Array of strings

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

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
  )

####### Specifying parameters of the aggregate function To use aggregateWindow() aggregate functions that don’t provide defaults for required parameters, for the fn parameter, define an anonymous function with columns and tables parameters that pipe-forwards tables into the aggregate 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: (columns, tables=<-) => tables |> percentile(percentile: 0.99, columns:columns)
  )

Function definition

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

InfluxQL aggregate functions
GROUP BY time()

This documentation is open source. See a typo? Please, open an issue.


Need help getting up and running? Get Support