Report container-scoped CPU and memory metrics in containers - #27425
Open
moesterheld wants to merge 6 commits into
Open
moesterheld wants to merge 6 commits into
moesterheld wants to merge 6 commits into
Conversation
…ners Fixes #27264 In containerized environments (e.g. Docker), the Cluster Configuration page displayed host-level CPU and memory figures rather than container-scoped usage and limits. In addition, Data Nodes could display a false warning about available memory exceeding heap size when direct cgroup filesystem reads failed. This change introduces container-aware metrics for both Graylog server and OpenSearch data nodes: - graylog2-server (CpuLoadGauge): Use OSHI's CgroupInfo to calculate container CPU usage deltas scaled by effective CPUs / CFS quota. Falls back to host CPU load ticks when not containerized. - data-node (NodeMetricsCollector): Inspect OpenSearch cgroup memory (limit_in_bytes, usage_in_bytes) and cpuacct stats to report container-scoped memory (total, used, free, used_percent) and CPU percent across ticks. - data-node (MetricsCollector): Retain NodeMetricsCollector instance across runs to track CPU usage deltas across consecutive samples. - data-node (OpensearchProcessImpl): Add OSHI CgroupInfo fallback to getContainerMemory() to accurately detect container limits and eliminate false-positive heap warning notifications. - Tests: Add unit tests for containerized CPU and memory reporting in both modules.
…d-cpu-and-memory-metrics
9 tasks
todvora
requested changes
Sep 18, 2026
todvora
left a comment
Contributor
There was a problem hiding this comment.
One style comment and one performance suggestion
todvora
self-requested a review
September 18, 2026 13:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #27389 — original work by @superezzdev, carried here unchanged so their
authorship is preserved.
Motivation
In containerized deployments, the Cluster Configuration page reported host-level CPU
and memory rather than the container's own limits and usage — on a host much larger
than the container, those figures are misleading. Data Nodes could additionally emit a
false "available memory exceeds heap size" warning when direct cgroup reads failed.
Approach
CPU and memory reporting is now cgroup-aware, falling back to the previous host-level
behavior when not running in a container:
CpuLoadGaugederives container CPU usage from OSHI'sCgroupInfo, scaling usagedeltas by the effective CPU count (CFS quota), and falls back to host CPU load ticks
outside containers.
NodeMetricsCollectorreads theos.cgroupsection of the OpenSearch node stats toreport container-scoped memory (total, used, free, used percent) and a delta-based
CPU percent.
MetricsCollectorretains theNodeMetricsCollectorinstance across runs soconsecutive samples are available for the CPU delta.
OpensearchProcessImplgains an OSHICgroupInfofallback ingetContainerMemory().Closes #27264
How Has This Been Tested?
locally, added tests
Screenshots (if appropriate):
Types of changes
Checklist: