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/dashboard.html | 314 ++++++++++++++++++++++++++++++++++++++++ internal/metrics/metrics.go | 8 + 2 files changed, 322 insertions(+) create mode 100644 internal/metrics/dashboard.html diff --git a/internal/metrics/dashboard.html b/internal/metrics/dashboard.html new file mode 100644 index 0000000..800b6df --- /dev/null +++ b/internal/metrics/dashboard.html @@ -0,0 +1,314 @@ + + + + + + Nostr Relay Metrics + + + +
+

Nostr Relay Metrics

+

Real-time relay statistics and performance metrics

+ +
+ +
+
+

Status

+
+ Relay + Online +
+
+ Uptime + -- +
+
+ +
+

Connections

+
+ Active + 0 +
+
+ Total + 0 +
+
+ +
+

Subscriptions

+
+ Active + 0 +
+
+ +
+

Requests

+
+ Total + 0 +
+
+ Success + 0 +
+
+ Errors + 0 +
+
+ +
+

Authentication

+
+ Success + 0 +
+
+ Failed + 0 +
+
+ +
+

Rate Limiting

+
+ Blocked + 0 +
+
+ +
+

Storage

+
+ Events + 0 +
+
+ DB Size + 0MB +
+
+ Deletions + 0 +
+
+ +
+

Performance

+
+ Avg Latency + 0ms +
+
+
+ +

Auto-refreshing every 5 seconds

+
+ + + + 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