forked from Galactic/galactic-bot
misc fixes to stats aggregation
This commit is contained in:
parent
721c1fa6c8
commit
fd8b6cb78d
@ -68,50 +68,65 @@ class BaseClient extends EventEmitter {
|
||||
case 'stats':
|
||||
this.aggregateStatistics(shard, message);
|
||||
break;
|
||||
case 'guild-live':
|
||||
this.getLiveGuild(shard, message);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async aggregateStatistics(shard, message) {
|
||||
console.log('AGGREGATE STATS!');
|
||||
|
||||
const managerData = {
|
||||
memory: process.memoryUsage().heapUsed, // Bytes
|
||||
uptime: Date.now() - this.readyAt,
|
||||
managedShards: this.shardingManager.shards.size
|
||||
const shardEval = (client) => {
|
||||
return {
|
||||
messages: client.channels.cache.reduce((amt, channel) => {
|
||||
amt += channel.messages?.cache.size || 0;
|
||||
return amt;
|
||||
}, 0),
|
||||
members: client.guilds.cache.reduce((amt, guild) => {
|
||||
amt += guild.members.cache.size;
|
||||
return amt;
|
||||
}, 0),
|
||||
users: client.users.cache.size,
|
||||
guilds: client.guilds.cache.size,
|
||||
channels: client.channels.cache.size,
|
||||
uptime: Math.floor(client.uptime/1000),
|
||||
memory: process.memoryUsage().heapUsed
|
||||
};
|
||||
};
|
||||
const shardData = await this.shardingManager.broadcastEval(shardEval);
|
||||
|
||||
const CPU = os.cpus();
|
||||
const freeMemory = os.freemem();
|
||||
const totalMemory = os.totalmem();
|
||||
const systemData = {
|
||||
cpu: CPU[0].model.trim(),
|
||||
threads: CPU.length,
|
||||
memory: {
|
||||
used: totalMemory - freeMemory,
|
||||
total: totalMemory
|
||||
const CPU = os.cpus(),
|
||||
freeMemory = os.freemem(),
|
||||
totalMemory = os.totalmem(),
|
||||
systemData = {
|
||||
cpu: CPU[0].model.trim(),
|
||||
threads: CPU.length,
|
||||
memory: {
|
||||
used: totalMemory - freeMemory,
|
||||
total: totalMemory
|
||||
},
|
||||
osType: os.type(),
|
||||
uptime: os.uptime(),
|
||||
hostname: os.hostname()
|
||||
},
|
||||
osType: os.type(),
|
||||
uptime: os.uptime(),
|
||||
hostname: os.hostname()
|
||||
};
|
||||
|
||||
const clientData = {
|
||||
library: {
|
||||
name: 'Discord.js',
|
||||
version: require('discord.js').version
|
||||
clientData = {
|
||||
library: {
|
||||
name: 'Discord.js',
|
||||
version: require('discord.js').version
|
||||
},
|
||||
shardData
|
||||
},
|
||||
shardData: []
|
||||
};
|
||||
|
||||
const databaseData = {
|
||||
|
||||
};
|
||||
managerData = {
|
||||
version: this.version,
|
||||
memory: process.memoryUsage().heapUsed, // Bytes
|
||||
uptime: Math.floor((Date.now() - this.readyAt) / 1000),
|
||||
managedShards: this.shardingManager.shards.size
|
||||
};
|
||||
|
||||
const data = {
|
||||
systemData,
|
||||
clientData,
|
||||
databaseData,
|
||||
managerData,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
@ -120,6 +135,15 @@ class BaseClient extends EventEmitter {
|
||||
|
||||
}
|
||||
|
||||
async getLiveGuild(shard, message) {
|
||||
|
||||
// TODO: Figure out what exactly this should return, waiting for further client implementation
|
||||
// const result = await this.shardingManager.broadcastEval((client) => {
|
||||
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
warn(message) {
|
||||
this.logger.write('warn', message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user