From 75fb3a583cf4e8a7ca34bedb3322d309bb170ed4 Mon Sep 17 00:00:00 2001 From: bndw Date: Sat, 14 Feb 2026 12:53:50 -0800 Subject: feat: add storage stats and average latency metrics Track and display storage and performance metrics that were previously showing zeros. Storage metrics: - Add GetStats() method to storage returning event count and DB size - Store database file path for size calculation - Update metrics every 30 seconds via goroutine in main.go - Display event count and DB size (MB) in dashboard Performance metrics: - Calculate average latency from histogram sum/count metrics - Display as milliseconds in dashboard - Formula: (duration_sum / duration_count) * 1000 Missing metrics (deferred): - Connections: requires connection lifecycle tracking (gRPC + WebSocket) - Deletions: count would need API change to ProcessDeletion Dashboard now shows accurate storage stats and request latency! --- cmd/relay/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'cmd/relay/main.go') diff --git a/cmd/relay/main.go b/cmd/relay/main.go index e4fe9bc..8948ebf 100644 --- a/cmd/relay/main.go +++ b/cmd/relay/main.go @@ -9,6 +9,7 @@ import ( "os" "os/signal" "syscall" + "time" "connectrpc.com/connect" "golang.org/x/net/http2" @@ -95,6 +96,23 @@ func main() { wsHandler := wshandler.NewHandler(store, subManager) if m != nil { wsHandler.SetMetrics(m) + + // Update storage stats periodically + go func() { + ticker := time.NewTicker(30 * time.Second) + defer ticker.Stop() + + // Update immediately on start + if stats, err := store.GetStats(context.Background()); err == nil { + m.UpdateStorageStats(stats.EventCount, stats.DBSizeBytes) + } + + for range ticker.C { + if stats, err := store.GetStats(context.Background()); err == nil { + m.UpdateStorageStats(stats.EventCount, stats.DBSizeBytes) + } + } + }() } var grpcDisplay, httpDisplay, wsDisplay string -- cgit v1.2.3