Skip to content

metrics: expose fractional cgroup CPU quota as process_available_cpu_cores - #136

Open
xiaozongyang wants to merge 1 commit into
VictoriaMetrics:masterfrom
xiaozongyang:feat/process-available-cpu-cores
Open

xiaozongyang wants to merge 1 commit into
VictoriaMetrics:masterfrom
xiaozongyang:feat/process-available-cpu-cores

Conversation

@xiaozongyang

Copy link
Copy Markdown

Expose process_available_cpu_cores as an unlabeled gauge through WriteProcMetrics, WriteProcessMetrics, and WritePrometheus(w, true) so process CPU usage can be compared with its cgroup CPU bandwidth limit, including fractional cores (e.g. 150000 / 100000 reports 1.5).

The collector supports cgroup v1 and v2, resolves membership against mountinfo (including mount roots and escaped paths), and uses the smallest readable positive quota among visible ancestors. Quotas are read on each collection; mountinfo is cached after one bounded read. Unlimited, missing or invalid limits fall back to runtime.NumCPU(), as do non-Linux platforms. Collection does not change GOMAXPROCS.

This reports CPU quota, not CPU reservation or Go scheduler parallelism; ancestor quotas can be shared with sibling cgroups. It does not combine CPU affinity/cpuset restrictions with the quota, and cannot discover ancestors hidden by the cgroup namespace.

Validation:

  • Tests cover v1/v2 fractional quotas, unlimited limits, ancestor limits, mount roots, hybrid hierarchies, malformed/missing data, quota changes, export opt-in/out, gauge metadata, and non-Linux fallback.
  • go test -race ./... and go vet ./... pass on macOS.
  • Linux amd64 and 386 test binaries cross-compile; Linux execution is left to CI because no local Linux container daemon is running.
  • golangci-lint run --new-from-rev=origin/master passes. Default full lint reports pre-existing issues in unchanged files.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 3 files

Re-trigger cubic

@xiaozongyang

Copy link
Copy Markdown
Author

hi @jiekun would you mind reviewing this PR?

@f41gh7 f41gh7 added the wontfix This will not be worked on label Oct 12, 2026
@f41gh7 f41gh7 self-assigned this Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants