PadMessageHandler: Register `activePads` metric only once

pull/5004/head
Richard Hansen 2021-04-12 17:31:30 -04:00
parent 6011d31b22
commit 4c4415e14a
1 changed files with 8 additions and 13 deletions

View File

@ -62,8 +62,15 @@ exports.socketio = () => {
const sessioninfos = {};
exports.sessioninfos = sessioninfos;
// Measure total amount of users
stats.gauge('totalUsers', () => Object.keys(socketio.sockets.sockets).length);
stats.gauge('activePads', () => {
const padIds = new Set();
for (const {padId} of Object.values(sessioninfos)) {
if (!padId) continue;
padIds.add(padId);
}
return padIds.size;
});
/**
* A changeset queue per pad that is processed by handleUserChanges()
@ -94,18 +101,6 @@ exports.handleConnect = (socket) => {
// Initialize sessioninfos for this new session
sessioninfos[socket.id] = {};
stats.gauge('activePads', () => {
const padIds = [];
for (const session of Object.keys(sessioninfos)) {
if (sessioninfos[session].padId) {
if (padIds.indexOf(sessioninfos[session].padId) === -1) {
padIds.push(sessioninfos[session].padId);
}
}
}
return padIds.length;
});
};
/**