Skip to content

node-mixin: Adjust memory used Dashboard to use MemAvailable #3830

Description

@braydonk

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.

Activity

  1. rogercoll commented on Sep 23, 2026

    @rogercoll

    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.

    Just wanted to add that MemAvailable is available since Linux Kernel 3.14, which was released on March 30, 2014. I would expect very few users would be affected, but I agree on keeping the fallback.

  2. ojasks commented on Sep 28, 2026

    @ojasks

    Hi @braydonk , I'd like to work on this if you're not already planning to. Before I start: the Linux Memory Usage panel is a stacked chart of used, buffers, cached and free, which currently sums to MemTotal. If "memory used" becomes MemTotal - MemAvailable, the stack would double-count buffers/cache/free. Would you prefer to keep the stack and adjust the other series, or unstack the panel? Also, the fallback in the recording rule includes node_memory_Slab_bytes, but the one proposed here doesn't. Which should the panel use?

  3. braydonk commented on Sep 29, 2026

    @braydonk
    Author

    Hi @ojasks,

    This hasn't received feedback from the Node Exporter maintainers yet. I would recommend not starting on anything until we confirm that they actually want this change. I am not a node exporter contributor, so I can't guarantee I am not missing some context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions