diff --git a/httpd/server.go b/httpd/server.go index 9b4a338..103e0f1 100644 --- a/httpd/server.go +++ b/httpd/server.go @@ -3,6 +3,7 @@ package httpd import ( "context" + "expvar" "fmt" "net" "net/http" @@ -36,8 +37,16 @@ var ( listener net.Listener sessionStore sessions.Store globalShutdown chan bool + + // ExpWebSocketConnectsCurrent tracks the number of open WebSockets + ExpWebSocketConnectsCurrent = new(expvar.Int) ) +func init() { + m := expvar.NewMap("http") + m.Set("WebSocketConnectsCurrent", ExpWebSocketConnectsCurrent) +} + // Initialize sets up things for unit tests or the Start() method func Initialize( cfg config.WebConfig, diff --git a/rest/socketv1_controller.go b/rest/socketv1_controller.go index de5245f..5bab16d 100644 --- a/rest/socketv1_controller.go +++ b/rest/socketv1_controller.go @@ -143,7 +143,12 @@ func MonitorAllMessagesV1( if err != nil { return err } - defer conn.Close() + httpd.ExpWebSocketConnectsCurrent.Add(1) + defer func() { + _ = conn.Close() + httpd.ExpWebSocketConnectsCurrent.Add(-1) + }() + log.Tracef("HTTP[%v] Upgraded to websocket", req.RemoteAddr) // Create, register listener; then interact with conn diff --git a/themes/bootstrap/public/metrics.js b/themes/bootstrap/public/metrics.js index ff01448..c6512bc 100644 --- a/themes/bootstrap/public/metrics.js +++ b/themes/bootstrap/public/metrics.js @@ -104,6 +104,7 @@ function displayMetrics(data, textStatus, jqXHR) { metric('memstatsHeapSys', data.memstats.HeapSys, sizeFilter, true); metric('memstatsHeapObjects', data.memstats.HeapObjects, numberFilter, true); metric('smtpConnectsCurrent', data.smtp.ConnectsCurrent, numberFilter, true); + metric('httpWebSocketConnectsCurrent', data.http.WebSocketConnectsCurrent, numberFilter, true); // Server-side history metric('smtpReceivedTotal', data.smtp.ReceivedTotal, numberFilter, false); diff --git a/themes/bootstrap/templates/root/status.html b/themes/bootstrap/templates/root/status.html index c39d185..d5845a6 100644 --- a/themes/bootstrap/templates/root/status.html +++ b/themes/bootstrap/templates/root/status.html @@ -107,6 +107,12 @@ $(document).ready(