Spaces:
Paused
Paused
Frank Kaumba
commited on
Update plugins
Browse files- plugins/uptime2.js +101 -0
plugins/uptime2.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const config = require('../config');
|
| 2 |
+
const { cmd, commands } = require('../command');
|
| 3 |
+
const os = require('os');
|
| 4 |
+
const { runtime } = require('../lib/functions');
|
| 5 |
+
const disk = require('disk-space');
|
| 6 |
+
const moment = require('moment');
|
| 7 |
+
|
| 8 |
+
cmd({
|
| 9 |
+
pattern: "system2",
|
| 10 |
+
react: "β‘",
|
| 11 |
+
alias: ["uptime2", "status2", "runtime2", "stats"],
|
| 12 |
+
desc: "Display comprehensive system statistics",
|
| 13 |
+
category: "main",
|
| 14 |
+
filename: __filename
|
| 15 |
+
}, async (conn, mek, m, {
|
| 16 |
+
from,
|
| 17 |
+
quoted,
|
| 18 |
+
body,
|
| 19 |
+
isCmd,
|
| 20 |
+
command,
|
| 21 |
+
args,
|
| 22 |
+
q,
|
| 23 |
+
isGroup,
|
| 24 |
+
sender,
|
| 25 |
+
senderNumber,
|
| 26 |
+
botNumber2,
|
| 27 |
+
botNumber,
|
| 28 |
+
pushname,
|
| 29 |
+
isMe,
|
| 30 |
+
isOwner,
|
| 31 |
+
groupMetadata,
|
| 32 |
+
groupName,
|
| 33 |
+
participants,
|
| 34 |
+
groupAdmins,
|
| 35 |
+
isBotAdmins,
|
| 36 |
+
isAdmins,
|
| 37 |
+
reply
|
| 38 |
+
}) => {
|
| 39 |
+
try {
|
| 40 |
+
const loadAvg = os.loadavg();
|
| 41 |
+
const cpuUsage = process.cpuUsage();
|
| 42 |
+
const cpuPercent = ((cpuUsage.user + cpuUsage.system) / (os.cpus().length * 1000000)).toFixed(2);
|
| 43 |
+
const networkInterfaces = os.networkInterfaces();
|
| 44 |
+
const primaryInterface = Object.values(networkInterfaces)[0][0];
|
| 45 |
+
const uptimeTotal = process.uptime();
|
| 46 |
+
const uptimeDays = Math.floor(uptimeTotal / (24 * 60 * 60));
|
| 47 |
+
const uptimeHours = Math.floor((uptimeTotal % (24 * 60 * 60)) / (60 * 60));
|
| 48 |
+
const uptimeMinutes = Math.floor((uptimeTotal % (60 * 60)) / 60);
|
| 49 |
+
const diskUsage = await new Promise((resolve) => {
|
| 50 |
+
disk.check('/', (err, result) => {
|
| 51 |
+
resolve(result || { free: 0, total: 0 });
|
| 52 |
+
});
|
| 53 |
+
});
|
| 54 |
+
const diskTotal = (diskUsage.total / (1024 * 1024 * 1024)).toFixed(2);
|
| 55 |
+
const diskFree = (diskUsage.free / (1024 * 1024 * 1024)).toFixed(2);
|
| 56 |
+
const diskUsed = (diskTotal - diskFree).toFixed(2);
|
| 57 |
+
|
| 58 |
+
```let status = `*ββββββββ SYSTEM STATUS βββββββ*
|
| 59 |
+
```
|
| 60 |
+
_SUBZERO BOT STATISTICS_
|
| 61 |
+
β° _Uptime:_ ${uptimeDays}d ${uptimeHours}h ${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)}MB / ${Math.round(require('os').totalmem / 1024 / 1024)}MB
|
| 62 |
+
_Disk Space:_ ${diskUsed}GB used of ${diskTotal}GB
|
| 63 |
+
_CPU Load:_ ${cpuPercent}%
|
| 64 |
+
_Load Average:_ ${loadAvg[0].toFixed(2)} (1m) ${loadAvg[1].toFixed(2)} (5m) ${os.type()} ${os.release()}
|
| 65 |
+
β Architecture: ${os.arch()}
|
| 66 |
+
β Platform: ${os.platform()}
|
| 67 |
+
β Hostname: ${os.hostname()}
|
| 68 |
+
β IP: ${primaryInterface.address}
|
| 69 |
+
_Bot Info:_
|
| 70 |
+
β Owner: MR FRANK
|
| 71 |
+
β Last Restart: ${moment().format('YYYY-MM-DD HH:mm:ss')}
|
| 72 |
+
β Node Version: ${process.version}
|
| 73 |
+
β Active Since: ${moment().subtract(uptimeTotal, 'seconds').format('YYYY-MM-DD HH:mm:ss')}
|
| 74 |
+
_β°βββββββββββββββββ_`;
|
| 75 |
+
|
| 76 |
+
```await conn.sendMessage(from, {
|
| 77 |
+
image: {
|
| 78 |
+
url: config.ALIVE_IMG
|
| 79 |
+
},
|
| 80 |
+
caption: status,
|
| 81 |
+
contextInfo: {
|
| 82 |
+
externalAdReply: {
|
| 83 |
+
title: "SubZero Bot Status",
|
| 84 |
+
body: "System Statistics & Performance Metrics",
|
| 85 |
+
mediaType: 1,
|
| 86 |
+
thumbnail: {
|
| 87 |
+
url: config.ALIVE_IMG
|
| 88 |
+
},
|
| 89 |
+
mediaUrl: config.WEBSITE_URL,
|
| 90 |
+
sourceUrl: config.WEBSITE_URL
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
}, {
|
| 94 |
+
quoted: mek
|
| 95 |
+
});
|
| 96 |
+
```
|
| 97 |
+
} catch (e) {
|
| 98 |
+
console.error('System status error:', e);
|
| 99 |
+
reply(`Error fetching system status: ${e.message}`);
|
| 100 |
+
}
|
| 101 |
+
});
|