How do I write a query that outputs average memory usage for instances over the past 24 hours? The following query displays the current memory usage
100 * (1 - ((node_memory_MemFree + node_memory_Cached + node_memory_Buffers) / node_memory_MemTotal))
For CPU, I was able to use irate
100 * (1 - avg(irate(node_cpu[24h])) BY (instance))
How do I use irate and avg for memory?
average memory usage for instances over the past 24 hours
You can use avg_over_time
:
100 * (1 - ((avg_over_time(node_memory_MemFree[24h]) + avg_over_time(node_memory_Cached[24h]) + avg_over_time(node_memory_Buffers[24h])) / avg_over_time(node_memory_MemTotal[24h])))
For CPU, I was able to use irate
irate
only looks at the last two samples, and that query is the inverse of how many modes you have and will be constant (it's always 0.1 on my kernel). You want
100 - (avg by (instance) (rate(node_cpu{job="node",mode="idle"}[5m])) * 100)
Note that this is a 5 minute moving average and you can change [5m]
to whatever period of time you are looking for such as [24h]
.