Skip to content

add CPU throttling metrics from cgroup cpu.stat#112

Draft
JayiceZ wants to merge 4 commits intomasterfrom
issue-10430
Draft

add CPU throttling metrics from cgroup cpu.stat#112
JayiceZ wants to merge 4 commits intomasterfrom
issue-10430

Conversation

@JayiceZ
Copy link
Copy Markdown

@JayiceZ JayiceZ commented Feb 16, 2026

fix VictoriaMetrics/VictoriaMetrics#10430


Summary by cubic

Expose CPU throttling metrics from cgroup cpu.stat for the current process. Works with cgroup v1 and v2 and only emits metrics when the cgroup CPU controller is enabled (addresses #10430).

  • New Features
    • Added metrics: process_cgroup_cpu_periods_total, process_cgroup_cpu_throttled_periods_total, process_cgroup_cpu_throttled_seconds_total.
    • Auto-detects v1/v2 cpu.stat and parses nr_periods, nr_throttled, and throttled time; converts to seconds and skips metrics if the CPU controller isn’t enabled.

Written for commit 085d533. Summary will update on new commits.

@JayiceZ JayiceZ marked this pull request as draft February 16, 2026 06:18
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 1 file

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="process_metrics_linux.go">

<violation number="1" location="process_metrics_linux.go:474">
P2: writeProcessCpuThrottleMetrics dereferences ctms without guarding against the nil return from getCgroupCpuStats, which can panic when no cgroup CPU stats are available.</violation>

<violation number="2" location="process_metrics_linux.go:476">
P2: `process_cgroup_cpu_throttled_seconds_total` reports non-second units (micro/milliseconds). Convert throttled_time to seconds (or store microseconds consistently and divide by 1e6 when writing) to avoid unit mismatch.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread process_metrics_linux.go
Comment thread process_metrics_linux.go
}
WriteGaugeUint64(w, "process_cgroup_cpu_periods_total", ctms.nrPeriods)
WriteGaugeUint64(w, "process_cgroup_cpu_throttled_periods_total", ctms.nrThrottled)
WriteGaugeUint64(w, "process_cgroup_cpu_throttled_seconds_total", ctms.throttledTime)
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Feb 16, 2026

Choose a reason for hiding this comment

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

P2: process_cgroup_cpu_throttled_seconds_total reports non-second units (micro/milliseconds). Convert throttled_time to seconds (or store microseconds consistently and divide by 1e6 when writing) to avoid unit mismatch.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At process_metrics_linux.go, line 476:

<comment>`process_cgroup_cpu_throttled_seconds_total` reports non-second units (micro/milliseconds). Convert throttled_time to seconds (or store microseconds consistently and divide by 1e6 when writing) to avoid unit mismatch.</comment>

<file context>
@@ -403,6 +420,62 @@ func readPSITotals(cgroupPath, statsName string) (uint64, uint64, error) {
+	}
+	WriteGaugeUint64(w, "process_cgroup_cpu_periods_total", ctms.nrPeriods)
+	WriteGaugeUint64(w, "process_cgroup_cpu_throttled_periods_total", ctms.nrThrottled)
+	WriteGaugeUint64(w, "process_cgroup_cpu_throttled_seconds_total", ctms.throttledTime)
+}
+
</file context>
Fix with Cubic

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 49.18033% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.02%. Comparing base (58ce999) to head (085d533).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
process_metrics_linux.go 49.18% 26 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #112      +/-   ##
==========================================
- Coverage   88.68%   87.02%   -1.67%     
==========================================
  Files          12       12              
  Lines        1388     1449      +61     
==========================================
+ Hits         1231     1261      +30     
- Misses        106      132      +26     
- Partials       51       56       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JayiceZ JayiceZ marked this pull request as ready for review March 2, 2026 05:27
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@JayiceZ JayiceZ marked this pull request as draft March 2, 2026 09:36
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.

Add CPU throttling metrics from cgroup cpu.stat (quota throttling proof)

1 participant