Skip to content

feat(metrics): collect host Pressure Stall Information (PSI) - #388

Closed
123123213weqw wants to merge 1 commit into
ccfos:mainfrom
123123213weqw:feat/host-psi-metrics
Closed

feat(metrics): collect host Pressure Stall Information (PSI)#388
123123213weqw wants to merge 1 commit into
ccfos:mainfrom
123123213weqw:feat/host-psi-metrics

Conversation

@123123213weqw

Copy link
Copy Markdown
Contributor

What

Adds a host Pressure Stall Information (PSI) collector reading /proc/pressure/{cpu,memory,io} and exposing some/full avg10/avg60/avg300 gauges and some/full total counters, labeled by resource.

Closes #384.

Why

Memory, CPU, and I/O contention stalls are the earliest signal of resource pressure, but huatuo had no PSI collection — operators only see the fallout (OOM, request timeout, node stall) after the fact. PSI directly quantifies how long tasks were stalled by resource contention.

How

  • New core/metrics/system_psi.go collector (system_psi), following the loadavg / cpu_stat host-metric pattern (FlagMetric, polled via Update()).
  • Reads /proc/pressure/{cpu,memory,io} via the vendored procfs.FS.PSIStatsForResource (re-exported PSIStats/PSILine type aliases from internal/procfs, alongside the existing FS/ProcMap aliases).
  • Emits, per resource: psi_some_avg10/avg60/avg300, psi_full_avg10/avg60/avg300 (gauges) and psi_some_total, psi_full_total (counters), labeled resource=cpu|memory|io. cpu has no full line (kernel limitation), so it produces only the some series.
  • Graceful degradation: if /proc/pressure is absent (PSI disabled at boot) the collector returns types.ErrNotSupported at registration → marked inactive, no impact on other collectors; per-resource read failures are skipped rather than failing the scrape.

Changes

  • core/metrics/system_psi.go (new) — collector + psiSamples mapping.
  • core/metrics/system_psi_test.go (new) — psiSamples cases (cpu some-only, memory some+full, empty stats).
  • internal/procfs/fs.go — re-export PSIStats, PSILine type aliases.

Verification

Built and tested on the wzu host (Linux 6.8, /proc/pressure live):

  • go build ./...
  • go test ./core/metrics/... ./internal/procfs/... (incl. new TestPSISamples)
  • go vet ./core/metrics/... ./internal/procfs/...
  • goimports / gofumpt / golangci-lint (v1.62.2) clean
  • make all — all 6 binaries + BPF objects build green

Out of scope (follow-ups, per the issue)

  • cgroup v2 *.pressure collection + container association.
  • Pressure state machine (configurable thresholds, sustained-trigger / hysteresis recovery).
  • Grafana panel + alerting examples.
  • Cardinality controls for high-density nodes (host PSI has only 3 resources, so not needed here).

Add a host PSI collector reading /proc/pressure/{cpu,memory,io} that exposes some/full avg10/avg60/avg300 gauges and some/full total counters, labeled by resource (cpu|memory|io). When the kernel lacks PSI support the collector registers as inactive (types.ErrNotSupported) so it does not affect other collectors; per-resource read failures degrade gracefully.

Reuses the vendored procfs.FS.PSIStatsForResource, re-exporting PSIStats/PSILine type aliases from internal/procfs alongside the existing FS/ProcMap aliases.

Host-only MVP for ccfos#384: cgroup v2 *.pressure collection, the pressure state machine, Grafana panels and alerting are deferred.

Closes ccfos#384.
@123123213weqw

Copy link
Copy Markdown
Contributor Author

整理我的开放 PR 队列,先关闭。分支保留,需要时重新打开或基于最新 main 重新提交。/ Cleaning up my open PR queue — closing for now. The branch is kept; will reopen or resubmit on latest main later.

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.

[功能建议]: 基于 PSI 的主机与 cgroup 资源压力预警

1 participant