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

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