Merge pull request #135 from thecodingmachine/track_server_load
Tracking nb users connected and server load
This commit is contained in:
commit
f2d7a9a732
@ -32,6 +32,7 @@
|
|||||||
"http-status-codes": "^1.4.0",
|
"http-status-codes": "^1.4.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"socket.io": "^2.3.0",
|
"socket.io": "^2.3.0",
|
||||||
|
"systeminformation": "^4.26.5",
|
||||||
"ts-node-dev": "^1.0.0-pre.44",
|
"ts-node-dev": "^1.0.0-pre.44",
|
||||||
"typescript": "^3.8.3",
|
"typescript": "^3.8.3",
|
||||||
"uuidv4": "^6.0.7"
|
"uuidv4": "^6.0.7"
|
||||||
|
@ -11,6 +11,7 @@ import {UserInterface} from "_Model/UserInterface";
|
|||||||
import {SetPlayerDetailsMessage} from "_Model/Websocket/SetPlayerDetailsMessage";
|
import {SetPlayerDetailsMessage} from "_Model/Websocket/SetPlayerDetailsMessage";
|
||||||
import {MessageUserJoined} from "../Model/Websocket/MessageUserJoined";
|
import {MessageUserJoined} from "../Model/Websocket/MessageUserJoined";
|
||||||
import {MessageUserMoved} from "../Model/Websocket/MessageUserMoved";
|
import {MessageUserMoved} from "../Model/Websocket/MessageUserMoved";
|
||||||
|
import si from "systeminformation";
|
||||||
|
|
||||||
enum SockerIoEvent {
|
enum SockerIoEvent {
|
||||||
CONNECTION = "connection",
|
CONNECTION = "connection",
|
||||||
@ -99,6 +100,14 @@ export class IoSocketController {
|
|||||||
this.Io.on(SockerIoEvent.CONNECTION, (socket: Socket) => {
|
this.Io.on(SockerIoEvent.CONNECTION, (socket: Socket) => {
|
||||||
let client : ExSocketInterface = socket as ExSocketInterface;
|
let client : ExSocketInterface = socket as ExSocketInterface;
|
||||||
this.sockets.set(client.userId, client);
|
this.sockets.set(client.userId, client);
|
||||||
|
|
||||||
|
// Let's log server load when a user joins
|
||||||
|
let srvSockets = this.Io.sockets.sockets;
|
||||||
|
console.log('A user joined (', Object.keys(srvSockets).length, ' connected users)');
|
||||||
|
si.currentLoad().then(data => console.log('Current load: ', data.avgload));
|
||||||
|
si.currentLoad().then(data => console.log('CPU: ', data.currentload, '%'));
|
||||||
|
// End log server load
|
||||||
|
|
||||||
/*join-rom event permit to join one room.
|
/*join-rom event permit to join one room.
|
||||||
message :
|
message :
|
||||||
userId : user identification
|
userId : user identification
|
||||||
@ -219,6 +228,13 @@ export class IoSocketController {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
this.sockets.delete(Client.userId);
|
this.sockets.delete(Client.userId);
|
||||||
|
|
||||||
|
// Let's log server load when a user leaves
|
||||||
|
let srvSockets = this.Io.sockets.sockets;
|
||||||
|
console.log('A user left (', Object.keys(srvSockets).length, ' connected users)');
|
||||||
|
si.currentLoad().then(data => console.log('Current load: ', data.avgload));
|
||||||
|
si.currentLoad().then(data => console.log('CPU: ', data.currentload, '%'));
|
||||||
|
// End log server load
|
||||||
});
|
});
|
||||||
|
|
||||||
// Let's send the user id to the user
|
// Let's send the user id to the user
|
||||||
|
326
back/yarn.lock
326
back/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user