Repository navigation
metrics: expose fractional cgroup CPU quota as process_available_cpu_cores - #136
Open
xiaozongyang wants to merge 1 commit into
Open
xiaozongyang wants to merge 1 commit into
xiaozongyang wants to merge 1 commit into
Conversation
Author
|
hi @jiekun would you mind reviewing this PR? |
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.
Expose
process_available_cpu_coresas an unlabeled gauge throughWriteProcMetrics,WriteProcessMetrics, andWritePrometheus(w, true)so process CPU usage can be compared with its cgroup CPU bandwidth limit, including fractional cores (e.g.150000 / 100000reports1.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 changeGOMAXPROCS.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:
go test -race ./...andgo vet ./...pass on macOS.golangci-lint run --new-from-rev=origin/masterpasses. Default full lint reports pre-existing issues in unchanged files.