-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetrics.js
40 lines (32 loc) · 1.06 KB
/
Metrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { collectDefaultMetrics, Gauge, Registry } = require('prom-client');
class Metrics {
constructor(client) {
this.client = client;
this.guildCount = new Gauge({
name: 'guild_count',
help: 'The number of servers the bot is in'
});
this.commandsUsed = new Gauge({
name: 'text_commands_used',
help: 'The number of temporary text commands used',
labelNames: ['command']
});
this.websocketEvents = new Gauge({
name: 'websocket_events',
help: 'The number of websocket events the bot received',
labelNames: ['type']
});
collectDefaultMetrics();
}
updateCommandUse(commands) {
Object.entries(commands).forEach(([command, count]) =>
this.commandsUsed.labels(command).set(count)
);
}
updateWebsocketEvents(events) {
Object.entries(events).forEach(([type, count]) =>
this.websocketEvents.labels(type).set(count)
);
}
}
module.exports = Metrics;