stats: activePads & lastDisconnected stats

pull/4639/head^2
John McLear 2021-02-06 19:53:52 +00:00 committed by GitHub
parent 5f58ce14d6
commit c969ae58c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -90,6 +90,19 @@ 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;
});
};
/**

View File

@ -22,6 +22,7 @@
const log4js = require('log4js');
const messageLogger = log4js.getLogger('message');
const stats = require('../stats');
/**
* Saves all components
@ -77,6 +78,11 @@ exports.setSocketIO = (_socket) => {
});
client.on('disconnect', () => {
// store the lastDisconnect as a timestamp, this is useful if you want to know
// when the last user disconnected. If your activePads is 0 and totalUsers is 0
// you can say, if there has been no active pads or active users for 10 minutes
// this instance can be brought out of a scaling cluster.
stats.gauge('lastDisconnect', () => Date.now());
// tell all components about this disconnect
for (const i in components) {
components[i].handleDisconnect(client);