From e87e288918d2e67d8fe2650962fbc4da36bd5b8b Mon Sep 17 00:00:00 2001 From: Steffen Date: Mon, 28 Dec 2020 20:18:45 +0100 Subject: [PATCH] fix channel metrics --- server/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/index.js b/server/index.js index a4a9644..fb80bc6 100644 --- a/server/index.js +++ b/server/index.js @@ -59,7 +59,15 @@ const metrics = { labelNames: ["name"], collect() { for (let channel in channels) { - this.set({ name: channel }, channels[channel].length); + this.set( + { name: channel }, + channels[channel].filter( + ws => + ws && + (ws.readyState === WebSocket.OPEN || + ws.readyState === WebSocket.CONNECTING) + ).length + ); } } }), @@ -217,7 +225,7 @@ wss.on("close", function close() { // prod mode with stats API if (process.env.NODE_ENV !== "development") { console.log("server starting"); - server.listen(8080); + server.listen(8081); server.on("request", (req, res) => { res.setHeader("Content-Type", register.contentType); register.metrics().then(out => res.end(out));