2021-06-24 10:09:10 +02:00
|
|
|
import { Counter, Gauge } from "prom-client";
|
2020-11-13 18:00:22 +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>;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.nbClientsGauge = new Gauge({
|
2021-06-24 10:09:10 +02:00
|
|
|
name: "workadventure_nb_sockets",
|
|
|
|
help: "Number of connected sockets",
|
|
|
|
labelNames: [],
|
2020-11-13 18:00:22 +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-11-13 18:00:22 +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-11-13 18:00:22 +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-11-13 18:00:22 +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-11-13 18:00:22 +01:00
|
|
|
}
|
2021-06-24 10:09:10 +02:00
|
|
|
|
2020-11-13 18:00:22 +01:00
|
|
|
decNbGroupsPerRoomGauge(roomId: string): void {
|
2021-06-24 10:09:10 +02:00
|
|
|
this.nbGroupsPerRoomGauge.dec({ room: roomId });
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
export const gaugeManager = new GaugeManager();
|