Repository navigation
Conversation
Inside containers the monitor reported host-level figures: disk usage summed every mount point (double-counting the overlay plus host bind-mounts on Linux, and sibling APFS volumes on macOS), while memory and CPU ignored cgroup limits and showed the whole host. - disk: read the root volume via disk.Usage instead of summing mounts - memory: honour the cgroup v2/v1 limit and working-set usage - cpu: derive effective cores and container usage from the CFS quota and cpu.stat All cgroup access is gated to Linux and fails safe to host metrics, so bare-metal and non-Linux deployments are unchanged. Adds cgroup_test.go covering v2/v1, unlimited sentinels, malformed input and fallbacks.
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.
Problem
Inside containers the system monitor reported host-level figures instead of the container's own resources:
/etc/hosts,/etc/resolv.conf) on Linux, and sibling APFS volumes / stray/Volumes/*mounts on macOS. A 512 GB Mac showed ~922 GB./proc/meminfo(host total) and ignored the cgroup limit: a--memory=512mcontainer reported 8 GB total with a host-wide used %.--cpus=2container reported 10 cores.Fix
disk.Usage(rootDiskPath())("/" on Unix, system drive on Windows) instead of enumerating and summing mount points — this is the disk the process can actually use (the container's writable layer under Docker).applyCgroupMemoryhonours the cgroup v2/v1 limit and working-set usage (current - inactive_file), and only overrides when a finite limit smaller than the host total is set.applyCgroupCPUderives effective cores from the CFS quota (cpu.max/cfs_quota_us÷period) and recomputes utilisation from thecpu.statusage delta over the sample window.Robustness
All cgroup access is gated to Linux (
runtime.GOOS == "linux") and every reader fails safe to host metrics on any problem — not Linux, no limit configured, unlimited sentinels, missing or malformed files, division by zero. Nothing panics. Bare-metal, non-Linux, and unlimited-container deployments are unchanged (host values, which are correct there).Tests
New
cgroup_test.gocovers v2/v1 parsing,max/-1/huge-sentinel unlimited cases, malformed input, period=0, limit≥host fallback, the Linux gate, andapplyCgroupMemoryoverrides.go test ./internal/monitor/andgo vetpass.Files
internal/monitor/cgroup.go(new) — cgroup v2/v1 readersinternal/monitor/cgroup_test.go(new) — robustness testsinternal/monitor/service.go— wire disk/memory/CPU collectors