feat(metrics): worker resource dashboard + pprof#58
Merged
Conversation
Add a standalone, auth-gated dashboard for inspecting running `pi --mode rpc` workers and process health. /api/metrics returns a non-blocking JSON snapshot (process goroutines/heap/SSE clients plus per-worker CPU/RSS via gopsutil); /metrics serves a self-contained polling page. CPU% is derived server-side from cumulative-CPU deltas to avoid gopsutil's blocking sampler, and idle workers past the reap TTL are flagged as zombies.
Expose Go's runtime profiler for deep "why is the app slow" dives. The index handler is mounted with the /api segment stripped because pprof.Index hard-codes the /debug/pprof/ prefix when routing to named profiles; cmdline/profile/symbol/trace are registered directly. All endpoints go through the existing auth middleware. The dashboard footer links to the profiler.
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.
Summary
pi --mode rpcworkers and overall process health — useful for spotting resource hogs, zombie/leaked workers, and diagnosing slowness.GET /metricsserves a self-contained HTML page (polls every 2s);GET /api/metricsreturns a non-blocking JSON snapshot: process goroutines/heap/SSE-clients/watched-files plus per-worker CPU/RSS via gopsutil.Percent(interval). Idle workers alive past the reap TTL are flagged as zombies.GET /api/debug/pprof/(auth-gated) for deep dives; the dashboard footer links to it.Design notes
workers.Manager.Snapshot()returns oneWorkerSnapshotper live worker. PID/uptime/idle come from an optionalinspectorinterface implemented by the real rpc worker; test fakes that don't implement it report zeros.processSamplerinterface (gopsutil-backed in prod, swappable for tests viaServer.SetMetricsSampler).pprof.Indexhard-codes the/debug/pprof/prefix, so the index handler is mounted with/apistripped;cmdline/profile/symbol/traceare registered directly.docs/dev/metrics-dashboard.md.Test plan
make check(vitest + go test + vet + build) greenManager.Snapshot(inspector / non-inspector / empty);/api/metricsJSON shape, auth gating, zombie flag, running-never-zombie, sampler-error degradation, CPU%-delta math, cache pruning; pprof index + named profile + auth gating/api/metricsvalid JSON,/api/debug/pprof/→ 200,/api/debug/pprof/heap→ real profile,/metricsfooter links to pprof/metricsin a browser with a couple of active chat workers and confirm CPU%/RSS/zombie rendering