Skip to content

Switch /metrics to promhttp.Handler() for full Prometheus output#1

Merged
iksnerd merged 1 commit into
mainfrom
prometheus-metrics
May 2, 2026
Merged

Switch /metrics to promhttp.Handler() for full Prometheus output#1
iksnerd merged 1 commit into
mainfrom
prometheus-metrics

Conversation

@iksnerd
Copy link
Copy Markdown
Owner

@iksnerd iksnerd commented May 2, 2026

Summary

  • Replaces hand-rolled Prometheus text formatter with promhttp.Handler() from github.com/prometheus/client_golang
  • Custom tracker metrics (tracker_announces_total, tracker_scrapes_total, tracker_registered_torrents, tracker_active_peers, tracker_swarms_total) now registered as typed prometheus.Counter / prometheus.Gauge / prometheus.GaugeFunc vars via promauto
  • Gets Go runtime metrics for free: go_goroutines, go_gc_*, go_memstats_*, process_cpu_seconds_total, etc.
  • Adds proper # HELP and # TYPE lines (previously missing)
  • Removes sync/atomic from tracker package — counters handled by prometheus internals

Test plan

  • go test ./... passes
  • curl http://localhost:8080/metrics returns full Prometheus output with both tracker_* and go_* metrics
  • TestMetricsHandler verifies all 5 custom metrics + go_goroutines are present

🤖 Generated with Claude Code

Replaces the hand-rolled text formatter with client_golang's promhttp.Handler(),
adding Go runtime metrics (goroutines, GC, memstats) and proper # TYPE lines
for free. Custom tracker metrics are now registered via promauto package vars.
@iksnerd iksnerd merged commit c1df8d6 into main May 2, 2026
1 check passed
@iksnerd iksnerd deleted the prometheus-metrics branch May 2, 2026 17:13
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.

1 participant