stateCount() function

The stateCount() function computes the number of consecutive records in a given state. The state is defined via the function fn. For each consecutive point that evaluates as true, the state count will be incremented. When a point evaluates as false, the state count is reset. The state count is added as an additional column to each record.

Function type: Transformation
Output data type: Integer

stateCount(fn: (r) => r._field == "state", label: "stateCount")

If the expression generates an error during evaluation, the point is discarded and does not affect the state count.

Parameters

fn

A single argument function that evaluates true or false to identify the state of the record. Records are passed to the function. Those that evaluate to true increment the state count. Those that evaluate to false reset the state count.

Data type: Function

label

The name of the column added to each record that contains the incremented state count.

Data type: String

Examples

from("monitor/autogen")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "server_state")
  |> stateCount()

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


Need help getting up and running? Get Support