Hello,
I have a year worth of data containing some discrete signals (1/0 ie. On/Off) stored in InfluxDB. Someone asked me to find all occurences where the signal was high (1) for longer than 2 minutes. Is it possible to answer this question with an InfluxQL query, or do I need special processing?
Thanks!
Jeroen
Jeroen,
I would do this with a Kapacitor job using the StateDuration node. The stateDuration node allows you to track the duration of a field at a specific value and will output a new field called “state_duration”. This can then be utilized in an alert or you could reemit the record into a different InfluxDB table.
Example:
stream
|from()
.measurement(‘discrete_signals_table’)
|groupBy(‘device_name’,‘signal_name’)
|stateDuration(lambda: “signal_state” == 1)
.unit(1m)
|influxDBOut()
.measurement(‘new_state_duration_table’)
You can also do this as a batch job using a batch node to look at your prior years data. With your new table, you can then report on the number of occurrences of the “high” state value.
1 Like