os#loadavg TypeScript Examples

The following examples show how to use os#loadavg. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Stats.ts    From yumeko with GNU Affero General Public License v3.0 6 votes vote down vote up
@constantly
    public async exec(msg: Message): Promise<Message> {
        const [usersSize, channelsSize, serversSize] = this.client.shard ?
            this.parseSizeEvaluate(await this.client.shard.broadcastEval(`[
                this.users.cache.map(x => x.id),
                this.channels.cache.size,
                this.guilds.cache.size
            ]`)) : [this.client.users.cache.size, this.client.channels.cache.size, this.client.guilds.cache.size];
        const usage = process.memoryUsage();
        const embed = new MessageEmbed()
            .setColor(this.client.config.color)
            .setTitle("♪ My Current Statistic")
            .setThumbnail(this.client.user!.displayAvatarURL())
            .setDescription(codeBlock("ascii", stripIndents`
                Shard          : ${Number(msg.guild!.shardID) + 1} / ${this.client.shard ? this.client.shard.count : 1}
                Memory Usage   : ${(usage.heapUsed / 1024 / 1024).toFixed(2)} / ${Math.round(100 * (usage.heapTotal / 1048576)) / 100} MB
                Uptime         : ${moment.duration(this.client.uptime).format("YY [years] MM [month] DD [days], hh:mm:ss")}
                CPU            : ${Math.round(loadavg()[0] * 100) / 100}%
                Users          : ${usersSize.toLocaleString()}
                Channels       : ${channelsSize.toLocaleString()}
                Servers        : ${serversSize.toLocaleString()}
                WS ping        : ${this.client.ws.ping.toFixed(2)}ms
                Node           : ${process.version}
            `));
        const owners: string[] = [];
        for (const own of this.client.config.owners) {
            const owner = this.client.users.cache.get(own) || await this.client.users.fetch(own, true).catch(() => undefined);
            if (!owner) continue;
            owners.push(`• ${msg.guild!.members.cache.has(owner.id) ? owner : owner.username} (${owner.id})`);
        }
        embed.addField("? Owners", owners.join("\n"))
            .addField("\u200B", "[Github](https://github.com/youKnowOwO) | [Repository](https://github.com/youKnowOwO/yumeko)");
        return msg.ctx.send(embed);
    }