I am trying to calculate in Grafana the time a device was up in the last 24h and then in a monthly basis. Ideally it should be 2 panels, one for 24h and one overall for the month.
The query I am using currently is: avg_over_time(up{instance="***.***.***.**:****"}[24h]) * 100
.
I copied it from the internet and I would like to do something similar for a month? Is this possible to achieve and if so, any pointers how to start?
I am trying to calculate in Grafana the time a device was up in the last 24h and then in a monthly basis. Ideally it should be 2 panels, one for 24h and one overall for the month.
The query I am using currently is: avg_over_time(up{instance="***.***.***.**:****"}[24h]) * 100
.
I copied it from the internet and I would like to do something similar for a month? Is this possible to achieve and if so, any pointers how to start?
1 Answer
Reset to default 1The avg_over_time function is documented here.
avg_over_time(range-vector): the average value of all points in the specified interval.
According to the range-vector documentation:
Range vector literals work like instant vector literals, except that they select a range of samples back from the current instant.
Whatever period (1s, 1m, 1h, 1d ...) you put in []
in a range-vector is the past period (24h
is the last 24 hours, 7d
is the last 7 days)
Now, you look at the instant vector literals, documented just above range vector literals.
Instant vector selectors allow the selection of a set of time series and a single sample value for each at a given timestamp (point in time).
You already have your query for 24h:
avg_over_time(up{instance="<identifier>}[24h]) * 100
So you just need to change the period from 24h to 30d, your query for a 30 day period becomes:
avg_over_time(up{instance="<identifier>"}[30d]) * 100
For periods, you use y,w,d,h,m,s,ms
(year, week, day, hour, minute, second, millisecond).
Note: 6m
does not mean 6 months but 6 minutes.
24h
replaced by30d
, miss your expectation? – markalex Commented Feb 10 at 14:00