diff options
| author | bndw <ben@bdw.to> | 2026-02-14 12:53:50 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-14 12:53:50 -0800 |
| commit | 75fb3a583cf4e8a7ca34bedb3322d309bb170ed4 (patch) | |
| tree | 175a9cd032779ee4f448a2fa931eeaef0c0f283a /cmd/relay/main.go | |
| parent | 40df56985402a31695a9a3bb13319bd2a3276305 (diff) | |
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!
Diffstat (limited to 'cmd/relay/main.go')
| -rw-r--r-- | cmd/relay/main.go | 18 |
1 files changed, 18 insertions, 0 deletions
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 ( | |||
| 9 | "os" | 9 | "os" |
| 10 | "os/signal" | 10 | "os/signal" |
| 11 | "syscall" | 11 | "syscall" |
| 12 | "time" | ||
| 12 | 13 | ||
| 13 | "connectrpc.com/connect" | 14 | "connectrpc.com/connect" |
| 14 | "golang.org/x/net/http2" | 15 | "golang.org/x/net/http2" |
| @@ -95,6 +96,23 @@ func main() { | |||
| 95 | wsHandler := wshandler.NewHandler(store, subManager) | 96 | wsHandler := wshandler.NewHandler(store, subManager) |
| 96 | if m != nil { | 97 | if m != nil { |
| 97 | wsHandler.SetMetrics(m) | 98 | wsHandler.SetMetrics(m) |
| 99 | |||
| 100 | // Update storage stats periodically | ||
| 101 | go func() { | ||
| 102 | ticker := time.NewTicker(30 * time.Second) | ||
| 103 | defer ticker.Stop() | ||
| 104 | |||
| 105 | // Update immediately on start | ||
| 106 | if stats, err := store.GetStats(context.Background()); err == nil { | ||
| 107 | m.UpdateStorageStats(stats.EventCount, stats.DBSizeBytes) | ||
| 108 | } | ||
| 109 | |||
| 110 | for range ticker.C { | ||
| 111 | if stats, err := store.GetStats(context.Background()); err == nil { | ||
| 112 | m.UpdateStorageStats(stats.EventCount, stats.DBSizeBytes) | ||
| 113 | } | ||
| 114 | } | ||
| 115 | }() | ||
| 98 | } | 116 | } |
| 99 | 117 | ||
| 100 | var grpcDisplay, httpDisplay, wsDisplay string | 118 | var grpcDisplay, httpDisplay, wsDisplay string |
