2021-06-24 10:09:10 +02:00
|
|
|
import { Counter, Gauge } from "prom-client";
|
2020-10-30 15:23:50 +01:00
|
|
|
|
|
|
|
//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>;
|
2020-11-12 14:51:19 +01:00
|
|
|
private nbRoomsGauge: Gauge<string>;
|
2020-10-30 15:23:50 +01:00
|
|
|
|
|
|
|
constructor() {
|
2020-11-12 14:51:19 +01:00
|
|
|
this.nbRoomsGauge = new Gauge({
|
2021-06-24 10:09:10 +02:00
|
|
|
name: "workadventure_nb_rooms",
|
|
|
|
help: "Number of active rooms",
|
2020-11-12 14:51:19 +01:00
|
|
|
});
|
2020-10-30 15:23:50 +01:00
|
|
|
this.nbClientsGauge = new Gauge({
|
2021-06-24 10:09:10 +02:00
|
|
|
name: "workadventure_nb_sockets",
|
|
|
|
help: "Number of connected sockets",
|
|
|
|
labelNames: [],
|
2020-10-30 15:23:50 +01:00
|
|
|
});
|
|
|
|
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"],
|
2020-10-30 15:23:50 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
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"],
|
2020-10-30 15:23:50 +01:00
|
|
|
});
|
|
|
|
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"],
|
2020-10-30 15:23:50 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-12 14:51:19 +01:00
|
|
|
incNbRoomGauge(): void {
|
|
|
|
this.nbRoomsGauge.inc();
|
|
|
|
}
|
|
|
|
decNbRoomGauge(): void {
|
|
|
|
this.nbRoomsGauge.dec();
|
|
|
|
}
|
|
|
|
|
2020-10-30 15:23:50 +01:00
|
|
|
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 });
|
2020-10-30 15:23:50 +01:00
|
|
|
}
|
2021-06-24 10:09:10 +02:00
|
|
|
|
2020-10-30 15:23:50 +01:00
|
|
|
decNbGroupsPerRoomGauge(roomId: string): void {
|
2021-06-24 10:09:10 +02:00
|
|
|
this.nbGroupsPerRoomGauge.dec({ room: roomId });
|
2020-10-30 15:23:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
export const gaugeManager = new GaugeManager();
|