Add PM2 metric tracking for Websocket Heartbeat

This commit is contained in:
Michael 2022-12-16 14:09:42 -05:00
parent 519c0520c5
commit a31a0d8d74
2 changed files with 14 additions and 3 deletions

View file

@ -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

View file

@ -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,
};