docs-v2/content/influxdb/cloud/reference/flux/stdlib/monitor/statechanges.md

1.8 KiB

title description aliases menu weight
monitor.stateChanges() function The `monitor.stateChanges()` function detects state changes in a stream of tables and outputs records that change from `fromLevel` to `toLevel`.
/influxdb/cloud/reference/flux/functions/monitor/statechanges/
influxdb_cloud_ref
name parent
monitor.stateChanges InfluxDB monitor
202

The monitor.stateChanges() function detects state changes in a stream of data with a _level column and outputs records that change from fromLevel to toLevel.

Function type: Transformation

import "influxdata/influxdb/monitor"

monitor.stateChanges(
  fromLevel: "any",
  toLevel: "any"
)

Parameters

fromLevel

The level to detect a change from. Defaults to "any".

Data type: String

toLevel

The level to detect a change to. The function output records that change to this level. Defaults to "any".

Data type: String

Examples

Detect when the state changes to critical
import "influxdata/influxdb/monitor"

monitor.from(start: -1h)
  |> monitor.stateChanges(toLevel: "crit")

{{< flex >}} {{% flex-content %}} Given the following input:

_time _level
0001 ok
0002 ok
0003 warn
0004 crit
{{% /flex-content %}}
{{% flex-content %}}
The following function outputs:
monitor.stateChanges(
  toLevel: "crit"
)
_time _level
0004 crit
{{% /flex-content %}}
{{< /flex >}}

Function definition

stateChanges = (fromLevel="any", toLevel="any", tables=<-) => {
  return
    if fromLevel == "any" and toLevel == "any" then tables |> stateChangesOnly()
    else tables |> _stateChanges(fromLevel: fromLevel, toLevel: toLevel)
}