node-mixin: Adjust `memory used` Dashboard to use `MemAvailable`
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}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: https://github.com/prometheus/node_exporter/blob/125a02099cde708ee9c99fddcc29a2703e92c576/docs/node-mixin/rules/rules.libsonnet#L43-L58
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.
Source: prometheus/node_exporter