Report server count anonymously with PM2

This commit is contained in:
Michael 2022-12-16 15:17:43 -05:00
parent a8f447e7c4
commit 8bb74d9cd8
2 changed files with 21 additions and 0 deletions

View file

@ -52,9 +52,13 @@ client.once(Events.ClientReady, c => {
metrics.websocketHeartbeatHist.update(latency);
}, 1000);
// Report current server count with PM2 (Servers counted anonymously)
metrics.serverCount.set(c.guilds.cache.size);
});
// Client "on" Events
// Someone used an interaction
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
@ -99,5 +103,17 @@ client.on(Events.InteractionCreate, async interaction => {
});
// Joined a server
client.on(Events.guildCreate, guild => {
// Report current server count with PM2 (Servers counted anonymously)
metrics.serverCount.set(guild.client.guilds.cache.size);
});
// Removed from a server
client.on(Events.guildDelete, guild => {
// Report current server count with PM2 (Servers counted anonymously)
metrics.serverCount.set(guild.client.guilds.cache.size);
});
// Log in to Discord with your client's token
client.login(token);

View file

@ -22,6 +22,10 @@ const websocketHeartbeatHist = io.histogram({
measurement: 'mean',
});
const serverCount = io.metric({
name : 'Server Count',
});
const interactionSuccess = function() {
interactionSuccessCounter.inc();
interactionSuccessMeter.mark();
@ -32,4 +36,5 @@ module.exports = {
interactionErrors,
interactionSuccess,
websocketHeartbeatHist,
serverCount,
};