I’m trying to implement exact the same thing and almost got it.
First of all take a look at the
changeDetect function: https://docs.influxdata.com/kapacitor/v1.5/nodes/change_detect_node/
I think something like
changeDetect('_tag') should work to group consecutive records.
Afterwards you could calculate the duration between two timestamps using the
elapsed function: https://docs.influxdata.com/kapacitor/v1.5/nodes/change_detect_node/#elapsed
The calculated duration records would reside in another measurement which could be joined on the time with the original measurement records. But that would result into:
As you can see the duration is added to the next node.
Using the function
stateDuration would be another option (sorry I’m not allowed to post more links).
But this node requires that you have at least two consecutive records for every point to calculate the duration, otherwise the duration is -1.
Maybe someone has an idea how to add the duration calculated using the elapsed function and the merge to the first of the compared records?