graylog2-server icon indicating copy to clipboard operation
graylog2-server copied to clipboard

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

Open fpetersen-gl opened this issue 3 months ago • 8 comments

Expected Behavior

When Graylog server and data nodes run in Docker, the Cluster Configuration page's CPU and memory figures should reflect each container's own usage and limits.

Current Behavior

The page shows host-level, and in one case flatly wrong, figures instead.

CPU (both node types) — host-wide, not container-scoped:

  • Graylog server: CpuLoadGauge reads OSHI's CentralProcessor.getSystemCpuLoadTicks(), sourced from /proc/stat, a host-wide counter.
  • Data node: NodeStatMetrics forwards OpenSearch's os.cpu.percent / os.cpu.load_average.1m, which OpenSearch's OsProbe also reads host-wide.

In a 2-node GL / 2-node DN cluster on one Docker host, all four nodes reported near-identical CPU — the host's, not each container's.

Memory (data node) — host-wide, and inflated by disk cache: NodeStatMetrics also forwards OpenSearch's os.mem.* fields. OsProbe computes these from com.sun.management.OperatingSystemMXBean.getFreePhysicalMemorySize()/getTotalPhysicalMemorySize(), which on Linux maps to /proc/meminfo's MemFree, not MemAvailable. MemFree excludes reclaimable page cache/buffers, which Linux — and OpenSearch/Lucene in particular — fills aggressively with disk cache. A data node with plenty of free capacity showed 98%+ memory used, driven almost entirely by page cache the OS would instantly reclaim if needed.

This produced two concrete false signals: a data node reported 15G total memory on a 16G host (host-wide, not its container's actual limit) and recommended raising the heap; separately, both data nodes showed 98%+ memory used with no real memory pressure.

Unaffected: heap metrics (jvm.memory.heap.* on GL server, jvm.mem.heap_* on data node) are JVM-internal and correct.

Possible Solution

OpenSearch's OsProbe already detects cgroups and exposes an os.cgroup block (memory.limit_in_bytes, memory.usage_in_bytes, cpu.cfs_quota_micros, cpuacct.usage_nanos) in _nodes/stats when running under a cgroup limit. NodeStatMetrics currently ignores this block — wiring it in would fix the data node's CPU and memory figures, including the cache-inflation problem, since cgroup memory accounting excludes reclaimable cache differently than MemFree does. The Graylog server side needs a separate cgroup-aware CPU read, since it has no equivalent field to fall back on.

Steps to Reproduce

  1. Run a 2-node Graylog server + 2-node data node cluster via Docker on one host.
  2. Open Cluster Configuration.
  3. Compare the reported CPU/memory to each container's actual docker stats or cgroup limits, and to free -h's available column on the host.
  4. Note that all nodes report near-identical, host-level CPU; data node memory shows 98%+ used despite ample free/reclaimable capacity.

Context

Misleading resource figures led to an unnecessary heap-size recommendation for a data node, based on host memory rather than the container's actual limit, and a false impression of memory pressure driven by disk cache. Related to https://github.com/Graylog2/quality-assurance/issues/82 - see also there for screenshots.

Your Environment

  • Graylog Version: 7.2.0-beta.1-1
  • Java Version: 21
  • OpenSearch Version: Data Node 7.2.0-beta-1.1
  • MongoDB Version: 8.3
  • Operating System: Docker on Linux
  • Browser version: Firefox 154.0.1

Checklist

  • [ ] This issue fix need to be backported.
  • [ ] Does this issue have security implications?

fpetersen-gl avatar Sep 03 '26 09:09 fpetersen-gl

Solution sounds reasonable, approx 30% of users are using containers

tellistone avatar Sep 03 '26 11:09 tellistone

I'd like to work on this issue.

I've reviewed the reported behavior and the affected metric paths. The current Cluster Configuration resource metrics appear to rely on host-level OS metrics when Graylog/Data Nodes are running inside Docker, which can result in misleading CPU and memory values.

I plan to investigate the existing CpuLoadGauge and NodeStatMetrics implementations and update the containerized resource metrics to use cgroup-aware CPU and memory information where available, while preserving the existing behavior for non-containerized environments.

For Data Nodes, I'll investigate wiring the relevant cgroup metrics exposed by OpenSearch into NodeStatMetrics. For Graylog server CPU metrics, I'll investigate an appropriate cgroup-aware source rather than relying on the host-wide /proc/stat values.

I'll also add/update tests covering container/cgroup resource reporting and verify that heap metrics remain unaffected.

I'd be happy to take ownership of this issue.

superezzdev avatar Sep 07 '26 11:09 superezzdev

Thanks for the detailed plan, @superezzdev — this is a great write-up and covers the right code paths on both the server and data node side. Go ahead and take it on!

A couple of pointers as you dig in:

  • Keep the non-containerized behavior intact, as you noted — that's important since most deployments aren't in Docker.
  • When you get to a PR, it'd help reviewers if you include a quick before/after comparison (e.g. docker stats vs. the reported values) alongside your tests.

Feel free to open a draft PR early if you want feedback on direction before finishing it up. Looking forward to seeing this!

fpetersen-gl avatar Sep 08 '26 10:09 fpetersen-gl

Hi @fpetersen-gl i'm working on this issue i'll have a PR soon

superezzdev avatar Sep 09 '26 17:09 superezzdev

Hey @superezzdev, thanks for contributing! We're moving to prioritise this issue in time for the next release, so our team will be looking at it shortly. Letting you know as don't want you to waste any subsequent time and effort duplicating work that we'll do anyway.

If you can provide your PR (at whatever level of completeness) within the next few days we'll seek to include your work in the solution.

Cheers!

tellistone avatar Sep 14 '26 13:09 tellistone

Hi @tellistone,

Thank you, and apologies for the delayed response. I was occupied with my university exams, so I wasn’t able to get back to you sooner. I really appreciate you following up and reminding me.

Please give me a few hours, and I’ll have a PR ready for you.

superezzdev avatar Sep 14 '26 13:09 superezzdev

Thanks again @superezzdev for your contribution, it will be included in the Graylog 7.2 release!

tellistone avatar Sep 28 '26 16:09 tellistone

Thank you @tellistone , Really appreciate it. I'm glad I could help get this fixed, and I'm looking forward to seeing it in the upcoming update.

Happy to contribute more whenever I can!

superezzdev avatar Sep 28 '26 16:09 superezzdev