Calculating total uptime for selected time frame and available data points

What I am looking for seems rather simple, but I fail to find any information in the documentation or forums on how to tackle this.

We would like to calculate the total availability of thousands of services through StatusCake for a given period. The API provides us with “periods”, which is start and end times of periods of up and down time. This is perfect and makes storing this information very efficient. (especially since most of the instance have had no or minimal downtime)

For any given service this would result in something like:

2020-05-14 16:01:14 – Up
2020-05-14 16:00:09 – Down
2020-03-16 11:36:23 – Up
2020-03-16 11:30:10 – Down
2020-01-12 05:31:18 – Up
2020-01-12 05:30:09 – Down
2019-10-11 11:01:14 – Up

So my plan is to store these events in InfluxDB with Up being 1 and Down being 0. And then use the integral function for the selected timeframe, which would return me the total uptime in seconds for the given timeframe.

For a service that has not been Down, there would only be a single data point, being

2019-10-11 11:01:14 – Up

The problem here is that it does not seem possible (or at least I haven’t found how) to get the number of seconds in the selected time frame in Grafana for which there was data available. What I am looking for is the first and last timestamp of collected data points to divide it by. Or a variable that stores this information already.

The aim is to get both the uptime for a given week, month, year for a single service, a group of services or all services.

Have you found a solution to this?