Monitor duration of state changes on windowing boundary

Hi Guys. I need to calculate % uptime of a measurement over a windowing period. A measurement can change state from “online” to offline" and this state can persist for an extended period of time. When measuring over a period, reversion to “online” may fall in the future, outside of the measurement window. How do I calculate the duration of the offline period, but clipped to the end of the measurement window?

E.g. timeline:
12:00 = online
13:00 = offline
17:00 = online, i.e. 4 hours of downtime.

If I am windowing from 12:00 until 16:00, I expect to see 3 hours of downtime. I am not sure how to do this in Flux.

I looked at stateDuration, but the documentation does not specify how windowing boundaries are handled. I looked at monitor.stateChanges but it is also not obvious how to calculate the duration of states when reversions fall outside the monitoring window.

Any assistance would be appreciated. Thanks!

Hi @PetrusTheron and welcome to the InfluxDB forum.

Your situation sounds similar to this one. Did you read through this already and/or try it?