partey_workadventure/back/src/Services/GaugeManager.ts

67 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-06-24 10:09:10 +02:00
import { Counter, Gauge } from "prom-client";
//this class should manage all the custom metrics used by prometheus
class GaugeManager {
private nbClientsGauge: Gauge<string>;
private nbClientsPerRoomGauge: Gauge<string>;
private nbGroupsPerRoomGauge: Gauge<string>;
private nbGroupsPerRoomCounter: Counter<string>;
private nbRoomsGauge: Gauge<string>;
constructor() {
this.nbRoomsGauge = new Gauge({
2021-06-24 10:09:10 +02:00
name: "workadventure_nb_rooms",
help: "Number of active rooms",
});
this.nbClientsGauge = new Gauge({
2021-06-24 10:09:10 +02:00
name: "workadventure_nb_sockets",
help: "Number of connected sockets",
labelNames: [],
});
this.nbClientsPerRoomGauge = new Gauge({
2021-06-24 10:09:10 +02:00
name: "workadventure_nb_clients_per_room",
help: "Number of clients per room",
labelNames: ["room"],
});
this.nbGroupsPerRoomCounter = new Counter({
2021-06-24 10:09:10 +02:00
name: "workadventure_counter_groups_per_room",
help: "Counter of groups per room",
labelNames: ["room"],
});
this.nbGroupsPerRoomGauge = new Gauge({
2021-06-24 10:09:10 +02:00
name: "workadventure_nb_groups_per_room",
help: "Number of groups per room",
labelNames: ["room"],
});
}
incNbRoomGauge(): void {
this.nbRoomsGauge.inc();
}
decNbRoomGauge(): void {
this.nbRoomsGauge.dec();
}
incNbClientPerRoomGauge(roomId: string): void {
this.nbClientsGauge.inc();
this.nbClientsPerRoomGauge.inc({ room: roomId });
}
decNbClientPerRoomGauge(roomId: string): void {
this.nbClientsGauge.dec();
this.nbClientsPerRoomGauge.dec({ room: roomId });
}
incNbGroupsPerRoomGauge(roomId: string): void {
2021-06-24 10:09:10 +02:00
this.nbGroupsPerRoomCounter.inc({ room: roomId });
this.nbGroupsPerRoomGauge.inc({ room: roomId });
}
2021-06-24 10:09:10 +02:00
decNbGroupsPerRoomGauge(roomId: string): void {
2021-06-24 10:09:10 +02:00
this.nbGroupsPerRoomGauge.dec({ room: roomId });
}
}
2021-06-24 10:09:10 +02:00
export const gaugeManager = new GaugeManager();