From 8270c14d86a45b53a97f653ae0c851a3b3044259 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 14 Aug 2019 15:22:03 +0100 Subject: [PATCH 1/2] add connected client count metric --- services/real-time/app/coffee/Router.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/real-time/app/coffee/Router.coffee b/services/real-time/app/coffee/Router.coffee index ad74ebffa1..11170d692d 100644 --- a/services/real-time/app/coffee/Router.coffee +++ b/services/real-time/app/coffee/Router.coffee @@ -56,6 +56,7 @@ module.exports = Router = client.emit("connectionAccepted") metrics.inc('socket-io.connection') + metrics.gauge('socket-io.clients', io.sockets.clients()?.length) logger.log session: session, client_id: client.id, "client connected" @@ -77,6 +78,7 @@ module.exports = Router = client.on "disconnect", () -> metrics.inc('socket-io.disconnect') + metrics.gauge('socket-io.clients', io.sockets.clients()?.length) WebsocketController.leaveProject io, client, (err) -> if err? Router._handleError null, err, client, "leaveProject" From f13e66b453dab6de7efdf9223e73d0508328d297 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 14 Aug 2019 15:34:23 +0100 Subject: [PATCH 2/2] fix client count so that result is zero when all clients have left --- services/real-time/app/coffee/Router.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/real-time/app/coffee/Router.coffee b/services/real-time/app/coffee/Router.coffee index 11170d692d..a7ed73c981 100644 --- a/services/real-time/app/coffee/Router.coffee +++ b/services/real-time/app/coffee/Router.coffee @@ -78,7 +78,7 @@ module.exports = Router = client.on "disconnect", () -> metrics.inc('socket-io.disconnect') - metrics.gauge('socket-io.clients', io.sockets.clients()?.length) + metrics.gauge('socket-io.clients', io.sockets.clients()?.length - 1) WebsocketController.leaveProject io, client, (err) -> if err? Router._handleError null, err, client, "leaveProject"