FEAT: added a prometheus gauge for the number of active rooms

This commit is contained in:
kharhamel 2020-11-12 14:51:19 +01:00
parent 6c6d046891
commit b064f01f97
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)