diff --git a/index.js b/index.js index 3e0c52c..c033300 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,14 @@ 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); + }); // Client "on" Events diff --git a/utils/pm2-metrics.js b/utils/pm2-metrics.js index 1ea1649..ee48260 100644 --- a/utils/pm2-metrics.js +++ b/utils/pm2-metrics.js @@ -7,17 +7,19 @@ const io = require('@pm2/io'); const interactionErrors = io.counter({ name: 'Interaction Errors (Since last restart)', - id: 'app/interactions/errors', }); const interactionSuccessCounter = io.counter({ name: 'Interaction Successful Runs (Since last restart)', - id: 'app/interactions/success', }); const interactionSuccessMeter = io.meter({ name: 'Successful Interactions per Second', - id: 'app/interactions/success', +}); + +const websocketHeartbeatHist = io.histogram({ + name: 'Websocket Heartbeat (ms)', + measurement: 'mean', }); const interactionSuccess = function() { @@ -29,4 +31,5 @@ module.exports = { io, interactionErrors, interactionSuccess, + websocketHeartbeatHist, }; \ No newline at end of file