Skip to content

Report container-scoped CPU and memory metrics in containers - #27425

Open
moesterheld wants to merge 6 commits into
masterfrom
fix/container-scoped-cpu-and-memory-metrics
Open

moesterheld wants to merge 6 commits into
masterfrom
fix/container-scoped-cpu-and-memory-metrics

Conversation

@moesterheld

Copy link
Copy Markdown
Contributor

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:

  • CpuLoadGauge derives container CPU usage from OSHI's CgroupInfo, scaling usage
    deltas by the effective CPU count (CFS quota), and falls back to host CPU load ticks
    outside containers.
  • NodeMetricsCollector reads the os.cgroup section of the OpenSearch node stats to
    report container-scoped memory (total, used, free, used percent) and a delta-based
    CPU percent.
  • MetricsCollector retains the NodeMetricsCollector instance across runs so
    consecutive samples are available for the CPU delta.
  • OpensearchProcessImpl gains an OSHI CgroupInfo fallback in getContainerMemory().

Closes #27264

How Has This Been Tested?

locally, added tests

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have requested a documentation update.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

superezzdev and others added 4 commits September 18, 2026 10:25
…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.
@moesterheld
moesterheld requested a review from todvora September 18, 2026 10:05

@todvora todvora left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One style comment and one performance suggestion

Comment thread graylog2-server/src/main/java/org/graylog2/periodical/CpuLoadGauge.java Outdated
@todvora
todvora self-requested a review September 18, 2026 13:03

@todvora todvora left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cluster Configuration page shows host-level CPU/memory instead of container-scoped values

3 participants