forked from Galactic/galactic-bot
further expand stats
This commit is contained in:
parent
c9f91fc490
commit
4340a2a5d3
@ -33,6 +33,7 @@ class StatsCommand extends Command {
|
||||
const { guild, author } = message;
|
||||
const { shard } = this.client;
|
||||
|
||||
//Shards eval
|
||||
const evalFunc = (thisArg) => {
|
||||
return {
|
||||
users: thisArg.users.cache.size,
|
||||
@ -43,6 +44,7 @@ class StatsCommand extends Command {
|
||||
};
|
||||
};
|
||||
|
||||
//Manager eval
|
||||
const mEvalFunc = (thisArg) => {
|
||||
return {
|
||||
memory: Math.floor(process.memoryUsage().heapUsed / 1024 / 1024),
|
||||
@ -53,6 +55,7 @@ class StatsCommand extends Command {
|
||||
const shardResults = await shard.broadcastEval(evalFunc).catch((error) => this.client.logger.error(error));
|
||||
const managerResult = await this.client.managerEval(`(${mEvalFunc})(this)`).catch((error) => this.client.logger.error(error));
|
||||
|
||||
//Current shard
|
||||
const mainValues = {
|
||||
uptime: this.client.resolver.timeAgo(Math.floor(managerResult.uptime / 1000), true, true, true),
|
||||
memory: managerResult.memory,
|
||||
@ -60,6 +63,7 @@ class StatsCommand extends Command {
|
||||
library: require('discord.js').version
|
||||
};
|
||||
|
||||
//All shards combined
|
||||
const shardValues = {
|
||||
cachedUsers: this.client.users.cache.size,
|
||||
guilds: this.client.guilds.cache.size,
|
||||
@ -68,6 +72,7 @@ class StatsCommand extends Command {
|
||||
memory: Math.floor(process.memoryUsage().heapUsed / 1024 / 1024)
|
||||
};
|
||||
|
||||
//Compile shard data
|
||||
const totalValues = shardResults.reduce((acc, curr) => {
|
||||
Object.entries(curr).forEach(([key, val]) => {
|
||||
if (!acc[key]) acc[key] = 0;
|
||||
@ -77,6 +82,7 @@ class StatsCommand extends Command {
|
||||
}, {});
|
||||
totalValues.uptime = this.client.resolver.timeAgo(Math.floor(totalValues.uptime / 1000), true, true, true);
|
||||
|
||||
//System information
|
||||
const CPU = os.cpus();
|
||||
const memoryFree = (os.freemem() / 1024 / 1024 / 1024).toFixed(1);
|
||||
const memoryTotal = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1);
|
||||
@ -94,6 +100,7 @@ class StatsCommand extends Command {
|
||||
hostname: os.hostname()
|
||||
};
|
||||
|
||||
//Command statistics - probably expand this further
|
||||
const commands = this.client.registry.components.filter((comp) => comp.type === 'command');
|
||||
|
||||
const commandValues = {
|
||||
@ -150,6 +157,40 @@ class StatsCommand extends Command {
|
||||
inline: true
|
||||
});
|
||||
|
||||
//Other
|
||||
const evalFunc2 = () => {
|
||||
let msg = 0,
|
||||
mem = 0;
|
||||
// eslint-disable-next-line no-return-assign
|
||||
this.channels.cache.forEach((c) => {
|
||||
msg += c.messages?.cache.size || 0
|
||||
});
|
||||
this.guilds.cache.forEach((g) => {
|
||||
mem += g.members.cache.size
|
||||
})
|
||||
return {
|
||||
cachedMessages: msg,
|
||||
cachedMembers: mem
|
||||
};
|
||||
};
|
||||
const result = await shard.broadcastEval(evalFunc2).catch((error) => this.client.logger.error(error.stack));
|
||||
console.log(result);
|
||||
const other = result.reduce((acc, curr) => {
|
||||
Object.entries(curr).forEach(([key, val]) => {
|
||||
if (!acc[key]) acc[key] = 0;
|
||||
acc[key] += val;
|
||||
});
|
||||
return acc;
|
||||
}, {});
|
||||
other['memberAvg'] = Math.floor(other.cachedMembers / shard.count);
|
||||
other['messageAvg'] = Math.floor(other.cachedMessages / shard.count);
|
||||
|
||||
embed.fields.push({
|
||||
name: message.format('C_STATS_CACHE'),
|
||||
value: message.format('C_STATS_CACHE_VALUE', other),
|
||||
inline: true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
message.embed(embed);
|
||||
|
@ -63,3 +63,12 @@ __**MongoDB**__
|
||||
**Entries:** {objects}
|
||||
**Average Entry Size:** {avgObjSize}MB
|
||||
**Total DB Size:** {totalSize}GB
|
||||
|
||||
[C_STATS_CACHE]
|
||||
__**Cache**__
|
||||
|
||||
[C_STATS_CACHE_VALUE]
|
||||
**Messages:** {cachedMessages}
|
||||
**Average caches messages per shard:** {messageAvg}
|
||||
**Members:** {cachedMembers}
|
||||
**Average cached members per shard:** {memberAvg}
|
Loading…
Reference in New Issue
Block a user