Percentage Uptime per month / Count

Hi,

My data in Influx comes from LibreNMS, which is polling devices for uptime every 5 minutes. The uptime is stored in seconds. I want to get an uptime percentage per month.
E.g.

  • Device is up for 30 days (or goes down and comes back up immediately), percentage=100%.

The way I currently have it setup, it will go down to 0% everytime the device goes down and start counting again.

Current config using InfluxQL:

SELECT mean("uptime") / 2592000 
FROM "uptime" 
WHERE ("hostname" = '10.237.150.20') AND $timeFilter 
GROUP BY time($__interval) fill(null)

An idea I’ve had to fix this;

  • Get a count of everytime the uptime goes to 0, the count increases every 300s (5min) and minuses from the total seconds per month (2592000)
  • I dont know if that will work.
  • I’m not very familiar with Flux but am happy to have a go.

I am making these graphs in Grafana but I can test in InfluxQL/Flux and make changes to suite Grafana.
Do you have any advice or queries I should try for this?

Thanks,
Arno.

Hello @Arnodb,
I’m sorry. I’m a little confused about what you’re trying to do here.
Can you provide a numerical example?

These functions might be interesting:

Hi Anaisdg,

Thanks for your reply.

I can’t really think of a numerical value but I can show a graph example.


In that image, it shows the graph on the right side going down and instantly counting again, so the uptime should be minimally impacted, not 20.2%.
The query I described in my original post was a Grafana query which gets the uptime (displayed in days in the second graph) and I made graphical changes in Grafana to display it as a percentage.
The query is set to select the last non null value and the default display is in days.

I’ve done the following yesterday:

  • Threshold is amount of seconds in a day, so it will not count if a device is down for a day.
threshold = 86400
from(bucket: "librenms")
  |> range(start: -30d)
  |> filter(fn: (r) => r.hostname == "au-brockman4-ves-sw-01" and r._field == "uptime")
  |> aggregateWindow(
        every: 5m,
        fn: (column, tables =<-) => tables
            |> reduce(
                identity: {above_threshold_count: 0.0},
                fn: (r, accumulator) => ({
                    above_threshold_count: if r._value >= threshold then
                        accumulator.above_threshold_count + 1.0
                    else
                        accumulator.above_threshold_count + 0.0,
                }),
            ),
    )

This somewhat does what I need it to but still seems to drop to 0 (_time=2022-04-11T00:20:00.000Z OR _time=2022-04-11T00:30:00.000Z)

I think this may be because there isnt an entry for that time?
See the below picture of this query which shows no entry for the two times mentioned above.

from(bucket: "librenms")
  |> range(start: -30d)
  |> filter(fn: (r) => r.hostname == "au-brockman4-ves-sw-01" and r._field == "uptime")

I tried the state duration and state count however I think I need a threshold for it to work properly?

from(bucket: "librenms")
  |> range(start: -10d)
  |> filter(fn: (r) => r.hostname == "au-brockman4-ves-sw-01" and r._field == "uptime")
    |> stateDuration(fn: (r) => r._measurement == "uptime", column: "stateDuration", unit: 5m)

How would I use the map function? Again I’m not very experienced in Flux…

Sorry for such a long reply…Thank you for your help so far!