diff --git a/index.js b/index.js index a030414..e29584a 100644 --- a/index.js +++ b/index.js @@ -7,13 +7,10 @@ const fs = require('node:fs'); const path = require('node:path'); -// Add pm2 metrics - this should NEVER track ANYTHING identifiable. This is purely for basic metrics and bot performance tracking -const metrics = require('./utils/pm2-metrics.js'); - // Use a custom logging script const logger = require('./utils/logging.js'); -// Listen for (Semi-)Permenant Interactions +// Listen for (Semi-)Permanent Interactions const interactionListener = require('./utils/interaction-trigger.js'); // Require the necessary discord.js classes @@ -47,17 +44,6 @@ for (const file of commandFiles) { client.once(Events.ClientReady, c => { logger.log(logger.logLevels.INFO, `${logger.colorText('Ready!', logger.textColor.Green)} Logged in as ${logger.colorText(c.user.tag, logger.textColor.Blue)}`); client.user.setPresence({ activities: [{ name: activity }], status: status }); - - // Track websocket heartbeat with PM2 Histogram - let latency = 0; - setInterval(function() { - latency = c.ws.ping; - metrics.websocketHeartbeatHist.update(latency); - }, 1000); - - // Report current server count with PM2 (Servers counted anonymously) - metrics.serverCount.set(c.guilds.cache.size); - }); // Client "on" Events @@ -71,14 +57,6 @@ client.on(Events.InteractionCreate, async interaction => { logger.log(logger.logLevels.ERROR, `No command matching ${interaction.commandName} was found.`); await interaction.reply({ content: `This command no longer exists! Please contact ${botOwner} to report that this is happening!`, ephemeral: true }); - // Report error to PM2 dashboard - metrics.interactionErrors.inc(); - metrics.io.notifyError(new Error('Interaction doesn\'t exist'), { - custom: { - interactionCommand: interaction.commandName, - }, - }); - return; } @@ -88,20 +66,7 @@ client.on(Events.InteractionCreate, async interaction => { catch (error) { logger.log(logger.logLevels.ERROR, error); await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); - - // Report error to PM2 dashboard - metrics.interactionErrors.inc(); - metrics.io.notifyError(new Error('Error executing interaction'), { - custom: { - interactionCommand: interaction.commandName, - error: error, - }, - }); } - // Successful Execution, report as a PM2 metric - // If the bot gets a lot of use, consider removing this for performance - metrics.interactionSuccess(); - } else if (interaction.isButton()) { interactionListener.buttonInteraction(interaction); @@ -111,17 +76,5 @@ 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); \ No newline at end of file diff --git a/utils/pm2-metrics.js b/utils/pm2-metrics.js deleted file mode 100644 index 8cad521..0000000 --- a/utils/pm2-metrics.js +++ /dev/null @@ -1,40 +0,0 @@ -/* -* Konpeki Discord Bot - Utility Definition File -* pm2-metrics.js - A place to keep all pm2 metrics and error definitions -*/ - -const io = require('@pm2/io'); - -const interactionErrors = io.counter({ - name: 'Interaction Errors (Since last restart)', -}); - -const interactionSuccessCounter = io.counter({ - name: 'Interaction Successful Runs (Since last restart)', -}); - -const interactionSuccessMeter = io.meter({ - name: 'Successful Interactions per Second', -}); - -const websocketHeartbeatHist = io.histogram({ - name: 'Avg. Websocket Heartbeat (ms) / 5 min.', - measurement: 'mean', -}); - -const serverCount = io.metric({ - name : 'Server Count', -}); - -const interactionSuccess = function() { - interactionSuccessCounter.inc(); - interactionSuccessMeter.mark(); -}; - -module.exports = { - io, - interactionErrors, - interactionSuccess, - websocketHeartbeatHist, - serverCount, -}; \ No newline at end of file