The following query returns per each time series m
the estimated percentage of raw samples greater than 0 during the last day:
avg_over_time(
(m >bool 0)[1d:10s]
) * 100
This query works in the following way:
It selects all the time series with the name m
over the last day. You can use any needed series selector instead of m
.
This query uses subquery feature.
It generates 24h/10s=8640
points per each selected time series from raw samples over the last 24 hours according to this algorithm.
It substitutes point values from step 2, which are bigger than 0 with 1, while replacing remaining point values with 0 according to >bool
comparison. See these docs for details.
It calculates the average value over points returned from step 3, individually per each selected time series. See avg_over_time docs.
The average value 0 means that the original time series has no values bigger than 0 during the last 24 hours. The average value 1 means that all the values for a particular time series are bigger than 0 during the last 24 hours.
It multiplies the average value per each matxhing time series by 100 in order to get the percentage of raw samples bigger than 0 over the last 24 hours.
P.S. The query can be simplified to the following one when using VictoriaMetrics - the Prometheus-like monitoring solution I work on:
share_gt_over_time(m[1d], 0) * 100
See share_gt_over_time() docs.