Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
fix: add node.js process memory usage per shard
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Aug 22, 2023
1 parent 6e3c465 commit c5a21ae
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/commands/system/shards.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ module.exports = {
.broadcastEval((shardClient) => {
/* eslint-disable no-undef */
let playerStats = player.generateStatistics();
const nodeProcessMemUsageInMb = (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2);
let shardInfo = {
shardId: shardClient.shard.ids[0],
memUsage: nodeProcessMemUsageInMb,
guildCount: shardClient.guilds.cache.size,
guildMemberCount: shardClient.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0),
playerStatistics: {
Expand All @@ -52,7 +54,7 @@ module.exports = {
(a, b) => b.playerStatistics.activeVoiceConnections - a.playerStatistics.activeVoiceConnections
);
}
logger.debug(results, `[Shard ${client.shard.ids[0]}] Fetched shardInfo from each shard.`);
logger.debug(`[Shard ${client.shard.ids[0]}] Fetched shardInfo from each shard.`);
})
.catch((error) => {
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
Expand All @@ -72,8 +74,9 @@ module.exports = {
string += `**Shard ${shard.shardId}** - Guilds: ${shard.guildCount.toLocaleString(
'en-US'
)} (${shard.guildMemberCount.toLocaleString('en-US')})\n`;
string += `**┗** Connections: ${shard.playerStatistics.activeVoiceConnections.toLocaleString('en-US')}\n`;
string += `**┗** Tracks: ${shard.playerStatistics.totalTracks.toLocaleString('en-US')}\n`;
string += `**Memory:** ${shard.memUsage.toLocaleString('en-US')} MB\n`;
string += `**┣** Connections: ${shard.playerStatistics.activeVoiceConnections.toLocaleString('en-US')}\n`;
string += `**┣** Tracks: ${shard.playerStatistics.totalTracks.toLocaleString('en-US')}\n`;
string += `**┗** Listeners: ${shard.playerStatistics.totalListeners.toLocaleString('en-US')}\n`;
return string;
}
Expand Down

0 comments on commit c5a21ae

Please sign in to comment.