summaryrefslogtreecommitdiffstats
path: root/internal/metrics/metrics.go
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-02-14 12:17:33 -0800
committerbndw <ben@bdw.to>2026-02-14 12:17:33 -0800
commit865b3da22881a1046c15e99bdd5fbc64aa374b73 (patch)
treeb82401b650780df42eebe778f9ae16512afab281 /internal/metrics/metrics.go
parentea4f508f5ee91b370c6912cde26b1a432380d037 (diff)
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
Diffstat (limited to 'internal/metrics/metrics.go')
-rw-r--r--internal/metrics/metrics.go8
1 files changed, 8 insertions, 0 deletions
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 @@
1package metrics 1package metrics
2 2
3import ( 3import (
4 _ "embed"
4 "net/http" 5 "net/http"
5 6
6 "github.com/prometheus/client_golang/prometheus" 7 "github.com/prometheus/client_golang/prometheus"
@@ -284,8 +285,15 @@ const (
284 StatusInvalidRequest RequestStatus = "invalid_request" 285 StatusInvalidRequest RequestStatus = "invalid_request"
285) 286)
286 287
288//go:embed dashboard.html
289var dashboardHTML []byte
290
287func (m *Metrics) Serve(addr, path string) error { 291func (m *Metrics) Serve(addr, path string) error {
288 mux := http.NewServeMux() 292 mux := http.NewServeMux()
289 mux.Handle(path, promhttp.Handler()) 293 mux.Handle(path, promhttp.Handler())
294 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
295 w.Header().Set("Content-Type", "text/html; charset=utf-8")
296 w.Write(dashboardHTML)
297 })
290 return http.ListenAndServe(addr, mux) 298 return http.ListenAndServe(addr, mux)
291} 299}