diff options
| -rw-r--r-- | internal/handler/websocket/handler.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go index a7b73ec..cb089b1 100644 --- a/internal/handler/websocket/handler.go +++ b/internal/handler/websocket/handler.go | |||
| @@ -26,6 +26,8 @@ type AuthStore interface { | |||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | type MetricsRecorder interface { | 28 | type MetricsRecorder interface { |
| 29 | IncrementConnections() | ||
| 30 | DecrementConnections() | ||
| 29 | IncrementSubscriptions() | 31 | IncrementSubscriptions() |
| 30 | DecrementSubscriptions() | 32 | DecrementSubscriptions() |
| 31 | SetActiveSubscriptions(count int) | 33 | SetActiveSubscriptions(count int) |
| @@ -114,6 +116,11 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
| 114 | } | 116 | } |
| 115 | defer conn.Close(websocket.StatusNormalClosure, "") | 117 | defer conn.Close(websocket.StatusNormalClosure, "") |
| 116 | 118 | ||
| 119 | // Track connection metrics | ||
| 120 | if h.metrics != nil { | ||
| 121 | h.metrics.IncrementConnections() | ||
| 122 | } | ||
| 123 | |||
| 117 | ctx := r.Context() | 124 | ctx := r.Context() |
| 118 | clientSubs := make(map[string]*subscription.Subscription) | 125 | clientSubs := make(map[string]*subscription.Subscription) |
| 119 | state := &connState{ | 126 | state := &connState{ |
| @@ -121,6 +128,12 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
| 121 | } | 128 | } |
| 122 | 129 | ||
| 123 | defer func() { | 130 | defer func() { |
| 131 | // Decrement connection count | ||
| 132 | if h.metrics != nil { | ||
| 133 | h.metrics.DecrementConnections() | ||
| 134 | } | ||
| 135 | |||
| 136 | // Clean up subscriptions | ||
| 124 | count := len(clientSubs) | 137 | count := len(clientSubs) |
| 125 | for subID := range clientSubs { | 138 | for subID := range clientSubs { |
| 126 | h.subs.Remove(subID) | 139 | h.subs.Remove(subID) |
