Currently, the memory used dashboard in the node-mixin for Linux uses the formula
$$\text{memory used} = \text{MemTotal} - \text{MemFree} - \text{Buffers} - \text{Cached}$$
|
'$datasource', |
|
||| |
|
( |
|
node_memory_MemTotal_bytes{%(nodeExporterSelector)s, instance="$instance", %(clusterLabel)s=~"$cluster"} |
|
- |
|
node_memory_MemFree_bytes{%(nodeExporterSelector)s, instance="$instance", %(clusterLabel)s=~"$cluster"} |
|
- |
|
node_memory_Buffers_bytes{%(nodeExporterSelector)s, instance="$instance", %(clusterLabel)s=~"$cluster"} |
|
- |
|
node_memory_Cached_bytes{%(nodeExporterSelector)s, instance="$instance", %(clusterLabel)s=~"$cluster"} |
|
) |
|
||| % config, |
The Linux kernel introduced MemAvailable specifically because the formula above is a less accurate estimation of usable memory. As a result, a more accurate number for memory usage would be
$$\text{memory used} = \text{MemTotal} - \text{MemAvailable}$$
We encouraged gopsutil to adopt the same formula to calculate usage and psutil adopted it at coincidentally the same time (but independent of our gopsutil suggestion).
I see that the memory utilization dashboard already accounts for this:
|
1 - ( |
|
( |
|
node_memory_MemAvailable_bytes{%(nodeExporterSelector)s} |
|
or |
|
( |
|
node_memory_Buffers_bytes{%(nodeExporterSelector)s} |
|
+ |
|
node_memory_Cached_bytes{%(nodeExporterSelector)s} |
|
+ |
|
node_memory_MemFree_bytes{%(nodeExporterSelector)s} |
|
+ |
|
node_memory_Slab_bytes{%(nodeExporterSelector)s} |
|
) |
|
) |
|
/ |
|
node_memory_MemTotal_bytes{%(nodeExporterSelector)s} |
Should the memory used dashboard do the same thing? I assume if it did something like this:
node_memory_MemTotal_bytes{%(nodeExporterSelector)s} - (
node_memory_MemAvailable_bytes{%(nodeExporterSelector)s}
or
(
node_memory_Buffers_bytes{%(nodeExporterSelector)s}
+
node_memory_Cached_bytes{%(nodeExporterSelector)s}
+
node_memory_MemFree_bytes{%(nodeExporterSelector)s}
)
)
That would make it so users on Linux environments that don't provide MemAvailable wouldn't be broken, but the rest could get a more accurate value that is similar to the calculation already being done in the utilization dashboard.
P.S. The way free used to calculated this in the past also included SReclaimable as part of the calculation alongside Cached, Buffers, and MemFree, and gopsutil used to do the same thing. I'm unsure whether it's worth it at this point to mess with the existing approximation formula in the dashboard, but I figured I would bring it up.
Currently, the
memory useddashboard in thenode-mixinfor Linux uses the formulanode_exporter/docs/node-mixin/lib/prom-mixin.libsonnet
Lines 126 to 137 in 125a020
The Linux kernel introduced
MemAvailablespecifically because the formula above is a less accurate estimation of usable memory. As a result, a more accurate number for memory usage would beWe encouraged
gopsutilto adopt the same formula to calculate usage andpsutiladopted it at coincidentally the same time (but independent of ourgopsutilsuggestion).I see that the memory utilization dashboard already accounts for this:
node_exporter/docs/node-mixin/rules/rules.libsonnet
Lines 43 to 58 in 125a020
Should the
memory useddashboard do the same thing? I assume if it did something like this:That would make it so users on Linux environments that don't provide
MemAvailablewouldn't be broken, but the rest could get a more accurate value that is similar to the calculation already being done in the utilization dashboard.P.S. The way
freeused to calculated this in the past also includedSReclaimableas part of the calculation alongsideCached,Buffers, andMemFree, andgopsutilused to do the same thing. I'm unsure whether it's worth it at this point to mess with the existing approximation formula in the dashboard, but I figured I would bring it up.