From 865b3da22881a1046c15e99bdd5fbc64aa374b73 Mon Sep 17 00:00:00 2001 From: bndw Date: Sat, 14 Feb 2026 12:17:33 -0800 Subject: feat: add metrics dashboard HTML page Add a real-time metrics dashboard accessible at the metrics server root. The dashboard displays relay statistics in a human-readable format with auto-refresh every 5 seconds. Features: - Active connections and subscriptions - Request counts (total, success, errors) - Authentication stats (success/failure) - Rate limiting hits - Storage metrics (events, DB size, deletions) - Clean, dark-themed UI with gradient accents - Auto-refresh and live uptime counter The dashboard is embedded using go:embed and served at / while Prometheus metrics continue to be available at /metrics. Example: http://localhost:9090/ for dashboard http://localhost:9090/metrics for raw metrics --- internal/metrics/metrics.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'internal/metrics/metrics.go') diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 9030d67..9030775 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -1,6 +1,7 @@ package metrics import ( + _ "embed" "net/http" "github.com/prometheus/client_golang/prometheus" @@ -284,8 +285,15 @@ const ( StatusInvalidRequest RequestStatus = "invalid_request" ) +//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) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Write(dashboardHTML) + }) return http.ListenAndServe(addr, mux) } -- cgit v1.2.3