Add stats output from interactive client

master
Håvar Aambø Fosstveit 2020-03-18 00:51:36 +01:00
parent 11de9a2dba
commit dd49fa3ea6
2 changed files with 27 additions and 5 deletions

View File

@ -14,6 +14,14 @@ module.exports = async function()
socket.pipe(process.stdout); socket.pipe(process.stdout);
socket.on('connect', () => process.stdin.setRawMode(true)); socket.on('connect', () => process.stdin.setRawMode(true));
socket.on('close', () => process.exit(0)); socket.on('close', () => process.exit(0));
socket.on('exit', () => socket.end()); socket.on('exit', () => socket.end());
if (process.argv && process.argv[2] === '--stats')
{
await socket.write('stats\n');
socket.end();
}
}; };

View File

@ -32,9 +32,6 @@ class Interactive
openCommandConsole() openCommandConsole()
{ {
this.log('\n[opening Readline Command Console...]');
this.log('type help to print available commands');
const cmd = readline.createInterface( const cmd = readline.createInterface(
{ {
input : this._socket, input : this._socket,
@ -162,6 +159,13 @@ class Interactive
break; break;
} }
case 'stats':
{
this.log(`rooms:${global.rooms.size}\npeers:${global.peers.size}`);
break;
}
case 'dumpRooms': case 'dumpRooms':
{ {
for (const room of global.rooms.values()) for (const room of global.rooms.values())
@ -572,12 +576,22 @@ class Interactive
log(msg) log(msg)
{ {
this._socket.write(`${colors.green(msg)}\n`); try
{
this._socket.write(`${colors.green(msg)}\n`);
}
catch (error)
{}
} }
error(msg) error(msg)
{ {
this._socket.write(`${colors.red.bold('ERROR: ')}${colors.red(msg)}\n`); try
{
this._socket.write(`${colors.red.bold('ERROR: ')}${colors.red(msg)}\n`);
}
catch (error)
{}
} }
} }