We have been struggling to create a good memory monitoring for our nodes running Docker components. We use Prometheus in combination with cadvisor and node_exporter.
What is the best way to determine the used memory per node?
Method 1: gives in our example around 42%
(1-(node_memory_MemAvailable_bytes/node_memory_MemTotal_bytes))*100
Method 2: gives around 80%
(1-((node_memory_MemFree_bytes+node_memory_Buffers_bytes+node_memory_Cached_bytes)/node_memory_MemTotal_bytes))*100
Q2: Why is this difference? What can I learn from this?
So I digged a bit deeper on determined the individual metrics:
Free memory: in our experiment was about 5%
(node_memory_MemFree_bytes/node_memory_MemTotal_bytes)*100
Buffered memory: around 0.002%
(node_memory_Buffers_bytes/node_memory_MemTotal_bytes)*100
Cached memory: around 15%
(node_memory_Cached_bytes/node_memory_MemTotal_bytes)*100
Availabable memory: 58%
(node_memory_MemAvailable_bytes/node_memory_MemTotal_bytes)*100
I would expect that FreeMem + BufferedMem + CachedMem would be around the AvailableMem. But that is not the outcome of this simple experiment.
Q3: Why is this not true?
It is said that the free memory on Linux consists of free mem + buffered mem + cached mem. When there is a short of memory, the cached memory could be freed, etc.