Reputation: 65
I'm currently trying to get the average percentage usage of RAM in the last month with the following query :
100 - ((avg_over_time(node_memory_MemAvailable_bytes{instance="...",job="..."}[4w]) * 100) / node_memory_MemTotal_bytes{instance="...",job="..."})
The query is working correctly, but now I would like to filter out the values that were collected during the night, in order to have a real usage percentage during the day : is it possible to get the average of the values collected only between 8AM and 8PM ?
Thanks in advance !
Mathias
Upvotes: 3
Views: 3715
Reputation: 10114
Since you can't have a range with holes (i.e. last 4 weeks but only 8 AM to 8 PM), you'd need to create a recorded rule that records available memory only during the day, then compute an avg_over_time
over the time series produced by said rule.
The rule is relatively easy to set up
node_memory_MemAvailable_bytes
and
hour(timestamp(node_memory_MemAvailable_bytes)) >= 8
and
hour(timestamp(node_memory_MemAvailable_bytes)) < 20
but it will not have any history initially, so you'll have to wait for a few days before you get any meaningful data out of it. Also note that this expression will filter for samples between 8 AM UTC and 8 PM UTC. You may need to adjust it to your timezone.
Upvotes: 5