partey_workadventure/pusher/src/Services/GaugeManager.ts

55 lines
1.7 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>;
constructor() {
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"],
});
}
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();