From eb666af39feed4be9c8c1354cf52d0ea38ab5d36 Mon Sep 17 00:00:00 2001 From: bndw Date: Sat, 14 Feb 2026 12:19:29 -0800 Subject: 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) --- internal/metrics/metrics.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'internal/metrics/metrics.go') 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 ( //go:embed dashboard.html var dashboardHTML []byte -func (m *Metrics) Serve(addr, path string) error { - mux := http.NewServeMux() - mux.Handle(path, promhttp.Handler()) - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { +func (m *Metrics) PrometheusHandler() http.Handler { + return promhttp.Handler() +} + +func (m *Metrics) DashboardHandler() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Write(dashboardHTML) }) +} + +func (m *Metrics) Serve(addr, path string) error { + mux := http.NewServeMux() + mux.Handle(path, m.PrometheusHandler()) + mux.Handle("/", m.DashboardHandler()) return http.ListenAndServe(addr, mux) } -- cgit v1.2.3