Merge pull request #413 from thecodingmachine/nbRoomsGauge

FEAT: added a prometheus gauge for the number of active rooms
This commit is contained in:
Kharhamel 2020-11-12 14:56:01 +01:00 committed by GitHub
commit 74ec363449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -6,8 +6,13 @@ class GaugeManager {
private nbClientsPerRoomGauge: Gauge<string>;
private nbGroupsPerRoomGauge: Gauge<string>;
private nbGroupsPerRoomCounter: Counter<string>;
private nbRoomsGauge: Gauge<string>;
constructor() {
this.nbRoomsGauge = new Gauge({
name: 'workadventure_nb_rooms',
help: 'Number of active rooms'
});
this.nbClientsGauge = new Gauge({
name: 'workadventure_nb_sockets',
help: 'Number of connected sockets',
@ -31,6 +36,13 @@ class GaugeManager {
});
}
incNbRoomGauge(): void {
this.nbRoomsGauge.inc();
}
decNbRoomGauge(): void {
this.nbRoomsGauge.dec();
}
incNbClientPerRoomGauge(roomId: string): void {
this.nbClientsGauge.inc();
this.nbClientsPerRoomGauge.inc({ room: roomId });

View File

@ -351,6 +351,7 @@ export class SocketManager {
world.leave(Client);
if (world.isEmpty()) {
this.Worlds.delete(Client.roomId);
gaugeManager.decNbRoomGauge();
}
}
//user leave previous room
@ -383,6 +384,7 @@ export class SocketManager {
world.tags = data.tags
world.policyType = Number(data.policy_type)
}
gaugeManager.incNbRoomGauge();
this.Worlds.set(roomId, world);
}
return Promise.resolve(world)