diff options
| author | bndw <ben@bdw.to> | 2026-02-14 12:19:29 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-14 12:19:29 -0800 |
| commit | eb666af39feed4be9c8c1354cf52d0ea38ab5d36 (patch) | |
| tree | c6488b73333882a6a245c0cd24157d2889a95639 /internal/metrics | |
| parent | 865b3da22881a1046c15e99bdd5fbc64aa374b73 (diff) | |
refactor: serve metrics on main HTTP port instead of separate port
Move metrics dashboard and Prometheus endpoint to the main HTTP server
for simplified deployment and single ingress configuration.
Changes:
- Add PrometheusHandler() and DashboardHandler() methods to Metrics
- Serve /dashboard on main HTTP port (was root on separate port)
- Serve /metrics on main HTTP port (was /metrics on separate port)
- Remove separate metrics server goroutine
- Update logging to show metrics paths on main HTTP port
Benefits:
- Single port/ingress needed for all HTTP traffic
- Simpler reverse proxy configuration
- Dashboard accessible alongside main relay endpoints
Endpoints on port 8080:
- / - WebSocket/index
- /nostr.v1.NostrRelay/* - Connect (gRPC-Web)
- /dashboard - Metrics dashboard (HTML)
- /metrics - Prometheus metrics (text)
Diffstat (limited to 'internal/metrics')
| -rw-r--r-- | internal/metrics/metrics.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 9030775..74f9ffb 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go | |||
| @@ -288,12 +288,20 @@ const ( | |||
| 288 | //go:embed dashboard.html | 288 | //go:embed dashboard.html |
| 289 | var dashboardHTML []byte | 289 | var dashboardHTML []byte |
| 290 | 290 | ||
| 291 | func (m *Metrics) Serve(addr, path string) error { | 291 | func (m *Metrics) PrometheusHandler() http.Handler { |
| 292 | mux := http.NewServeMux() | 292 | return promhttp.Handler() |
| 293 | mux.Handle(path, promhttp.Handler()) | 293 | } |
| 294 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | 294 | |
| 295 | func (m *Metrics) DashboardHandler() http.Handler { | ||
| 296 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| 295 | w.Header().Set("Content-Type", "text/html; charset=utf-8") | 297 | w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| 296 | w.Write(dashboardHTML) | 298 | w.Write(dashboardHTML) |
| 297 | }) | 299 | }) |
| 300 | } | ||
| 301 | |||
| 302 | func (m *Metrics) Serve(addr, path string) error { | ||
| 303 | mux := http.NewServeMux() | ||
| 304 | mux.Handle(path, m.PrometheusHandler()) | ||
| 305 | mux.Handle("/", m.DashboardHandler()) | ||
| 298 | return http.ListenAndServe(addr, mux) | 306 | return http.ListenAndServe(addr, mux) |
| 299 | } | 307 | } |
