fix channel metrics

This commit is contained in:
Steffen 2020-12-28 20:18:45 +01:00
parent 7cc59b05cf
commit e87e288918
1 changed files with 10 additions and 2 deletions

View File

@ -59,7 +59,15 @@ const metrics = {
labelNames: ["name"], labelNames: ["name"],
collect() { collect() {
for (let channel in channels) { 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 // prod mode with stats API
if (process.env.NODE_ENV !== "development") { if (process.env.NODE_ENV !== "development") {
console.log("server starting"); console.log("server starting");
server.listen(8080); server.listen(8081);
server.on("request", (req, res) => { server.on("request", (req, res) => {
res.setHeader("Content-Type", register.contentType); res.setHeader("Content-Type", register.contentType);
register.metrics().then(out => res.end(out)); register.metrics().then(out => res.end(out));