Calculate Uptime by calculating presence of entries

Hello There,

I’m kind of totally new to Grafana and InfluxDB.
I’m looking to calculate the availability of IoT devices. I have a table in influxdb with the battery that they have left.

when there is no battery anymore, the devices goes off and I have no entries anymore.

I’m thinking of a query that count queries on every range (let’s say 30min) and then can give me a percentage of uptime. (down if queries = 0 , up if queries > 0)

Any idea of things to search to help me build the query? I think it’s not that hard i’m just having difficulties to get started !



Let’s say you have a parameter that is 1 when the device is on and is 0 when the device is off.
You have this parameter saved in a tsdb every x minutes.
Then, availability for a specific interval = sum(parameter)/count(parameter). If you need in %, just multiply with 100.

I hope that helps.