feat(metrics): opt-in Prometheus /metrics on the loopback fleet server - #62
Conversation
Exposes earnings (per-platform balance + USD total/today/month), per-service health score + uptime%, and fleet online/offline counts as Prometheus gauges for a homelab Grafana. Hand-rolled text exposition (no new dependency); reuses computeEarningsSummary so the FX logic is not duplicated. Gated by a new MetricsEnabled config flag (default false); the /metrics route is only registered when enabled (404 otherwise). Unauthenticated by Prometheus convention, on the loopback-default fleet bind.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62 +/- ##
==========================================
+ Coverage 65.05% 66.38% +1.32%
==========================================
Files 8 9 +1
Lines 2012 2109 +97
==========================================
+ Hits 1309 1400 +91
- Misses 611 614 +3
- Partials 92 95 +3
🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAdds an opt-in Prometheus ChangesPrometheus metrics endpoint
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Adds an opt-in Prometheus
/metricsendpoint on the existing loopback fleet server, so a homelab Prometheus/Grafana can scrape the app. The production CashPilot has this; the rewrite didn't. (Gap analysis.)cashpilot_prefix, mirroring the original):cashpilot_up,cashpilot_collect_interval_minutes,cashpilot_earnings_usd_total/_today/_month,cashpilot_service_balance{platform,currency}(+cashpilot_service_error{platform}for a latest-error platform, no bogus balance),cashpilot_service_health_score{slug},cashpilot_service_uptime_percent{slug},cashpilot_fleet_devices{status},cashpilot_fleet_device_last_seen_seconds{device}.text/plain; version=0.0.4).computeEarningsSummary— the FX/accrual logic is not duplicated.MetricsEnabledconfig flag (default false); the route is only registered when enabled → 404 otherwise. Unauthenticated by Prometheus convention, on the loopback-default bind.Tests
Handler output (metric lines, content-type, error-row handling, label escaping, nil-store safety, non-GET rejection) + the mux gating (404 disabled / 200 enabled) + config default. Verified on macOS:
go build/vet/test -race ./...all green.Summary by CodeRabbit
New Features
/metricsendpoint on the fleet server.Bug Fixes