Skip to content

Commit 4fccc89

Browse files
committed
feat: update stast command
1 parent 325d0ea commit 4fccc89

1 file changed

Lines changed: 51 additions & 37 deletions

File tree

src/commands/stats.ts

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message } from "../../types/message"
1+
import { Message } from "../../types/message";
22
import log from "../components/utils/log";
33
import os from "os";
44
import si from "systeminformation";
@@ -8,7 +8,7 @@ import { commands } from "../index";
88

99
export const info = {
1010
command: "stats",
11-
description: "Get system statistics including CPU, RAM, GPU, and more.",
11+
description: "Get system and Node.js runtime statistics.",
1212
usage: "stats",
1313
example: "stats",
1414
role: "user",
@@ -17,49 +17,63 @@ export const info = {
1717

1818
export default async function (msg: Message) {
1919
if (!/^stats$/i.test(msg.body)) return;
20+
21+
// Node.js runtime stats
22+
const mem = process.memoryUsage();
23+
const cpu = process.cpuUsage();
24+
const uptime = process.uptime();
25+
26+
const nodeStats = {
27+
rss: (mem.rss / 1024 ** 2).toFixed(2), // MB
28+
heapUsed: (mem.heapUsed / 1024 ** 2).toFixed(2),
29+
heapTotal: (mem.heapTotal / 1024 ** 2).toFixed(2),
30+
external: (mem.external / 1024 ** 2).toFixed(2),
31+
arrayBuffers: (mem.arrayBuffers / 1024 ** 2).toFixed(2),
32+
cpuUser: (cpu.user / 1000).toFixed(2), // ms
33+
cpuSystem: (cpu.system / 1000).toFixed(2), // ms
34+
uptime: `${Math.floor(uptime / 60)}m ${Math.floor(uptime % 60)}s`,
35+
nodeVersion: process.version,
36+
platform: process.platform,
37+
};
38+
39+
// System stats
2040
const stats = {
21-
OS: os.release(),
22-
arch: os.arch(),
23-
cpu: os.cpus(),
2441
usedMemory: os.totalmem() - os.freemem(),
2542
totalMemory: os.totalmem(),
43+
cpu: os.cpus(),
2644
};
2745

28-
const [
29-
gpuInfo,
30-
osInfo,
31-
shell,
32-
networkInterfaces,
33-
userCount,
34-
blockUserCount,
35-
] = await Promise.all([
36-
si.graphics(),
37-
si.osInfo(),
38-
si.shell(),
39-
si.networkInterfaces(),
40-
getUserCount(),
41-
getBlockUserCount()
42-
]);
46+
const [gpuInfo, osInfo, shell, networkInterfaces, userCount, blockUserCount] =
47+
await Promise.all([
48+
si.graphics(),
49+
si.osInfo(),
50+
si.shell(),
51+
si.networkInterfaces(),
52+
getUserCount(),
53+
getBlockUserCount(),
54+
]);
4355

4456
const statsMessage = `
45-
\`System Monitor\`
57+
\`System Monitor\`
58+
59+
OS: ${osInfo.distro} ${osInfo.kernel}
60+
CPU: ${stats.cpu[0].model}
61+
GPU: ${gpuInfo.controllers.map((c) => c.model).join(", ")}
62+
RAM: ${(stats.usedMemory / 1024 ** 3).toFixed(2)} GB / ${(stats.totalMemory / 1024 ** 3).toFixed(2)} GB
63+
VRAM: ${gpuInfo.controllers.map((c) => c.vram).join(", ")} MB
64+
Shell: ${shell}
65+
Network: ${networkInterfaces.map((iface) => `${iface.iface} ${iface.speed} Mbps`).join(", ")}
66+
Commands: ${Object.keys(commands).length}
67+
Users: ${userCount}
68+
Blocked Users: ${blockUserCount}
4669
47-
OS: ${osInfo.distro} ${osInfo.kernel}
48-
CPU: ${stats.cpu[0].model}
49-
GPU: ${gpuInfo.controllers.map((c) => c.model).join(", ")}
50-
RAM: ${(stats.usedMemory / 1024 ** 3).toFixed(2)} GB / ${(
51-
stats.totalMemory /
52-
1024 ** 3
53-
).toFixed(2)} GB
54-
VRam: ${gpuInfo.controllers.map((c) => c.vram).join(", ")} MB
55-
Shell: ${shell}
56-
Network: ${networkInterfaces
57-
.map((iface) => `${iface.iface} ${iface.speed} Mbps`)
58-
.join(", ")}
59-
Commands: ${Object.keys(commands).length}
60-
Users: ${userCount}
61-
Blocked Users: ${blockUserCount}
62-
`;
70+
\`Node.js Runtime\`
71+
Node: ${nodeStats.nodeVersion} on ${nodeStats.platform}
72+
Uptime: ${nodeStats.uptime}
73+
Memory: ${nodeStats.heapUsed} MB / ${nodeStats.heapTotal} MB (RSS: ${nodeStats.rss} MB)
74+
External: ${nodeStats.external} MB, ArrayBuffers: ${nodeStats.arrayBuffers} MB
75+
CPU Time: User ${nodeStats.cpuUser} ms | System ${nodeStats.cpuSystem} ms
76+
`;
6377

6478
await msg.reply(statsMessage);
6579
}

0 commit comments

Comments
 (0)