From e243eb02f729b465008b7833e09d367d3e8d87e9 Mon Sep 17 00:00:00 2001 From: 7cc5c4f330d47060 Date: Thu, 5 Sep 2024 15:50:11 -0400 Subject: [PATCH] Add memory to serverinfo --- commands/about.js | 18 +++++++++++++++++- lang/en-US.json | 3 +++ util/memoryconvert.js | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 util/memoryconvert.js diff --git a/commands/about.js b/commands/about.js index a7d981f..05abe9d 100644 --- a/commands/about.js +++ b/commands/about.js @@ -1,6 +1,7 @@ const os = require('os') const cp = require('child_process') const { getMessage, formatTime } = require('../util/lang.js') +const memoryconvert = require('../util/memoryconvert.js') const fs = require('fs') const botVersion = require('../util/version.js') const version = require('../version.json') @@ -155,6 +156,21 @@ const aboutServer = function (c) { }) } + // System memory (total) + displayInfo('command.about.serverInfo.totalMem', () => { + return memoryconvert(os.totalmem()) + }) + + // System memory (free) + displayInfo('command.about.serverInfo.freeMem', () => { + return memoryconvert(os.freemem()) + }) + + // System memory (used) + displayInfo('command.about.serverInfo.usedMem', () => { + return memoryconvert(os.totalmem() - os.freemem()) + }) + // Username and UID displayInfo('command.about.serverInfo.osUsername', () => { return `${os.userInfo().username} (${os.userInfo().uid})` @@ -179,7 +195,7 @@ const aboutServer = function (c) { displayInfo('command.about.serverInfo.runTime', () => { return formatTime(process.uptime() * 1000, c.lang) }) - + // System uptime displayInfo('command.about.serverInfo.upTime', () => { return formatTime(os.uptime() * 1000, c.lang) diff --git a/lang/en-US.json b/lang/en-US.json index a077820..da20815 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -98,6 +98,9 @@ "command.about.serverInfo.kernelVer": "Kernel version", "command.about.serverInfo.processor": "CPU", "command.about.serverInfo.arch": "Architecture", + "command.about.serverInfo.totalMem": "Total memory", + "command.about.serverInfo.freeMem": "Free memory", + "command.about.serverInfo.usedMem": "Used memory", "command.about.serverInfo.osUsername": "Username", "command.about.serverInfo.hostName": "Hostname", "command.about.serverInfo.workingDir": "Working directory", diff --git a/util/memoryconvert.js b/util/memoryconvert.js new file mode 100644 index 0000000..43269e0 --- /dev/null +++ b/util/memoryconvert.js @@ -0,0 +1,15 @@ +module.exports = function (bytes) { + if(bytes >= 1125899906842624){ // Petabytes + return `${Math.round(bytes / 1125899906842624 * 100) / 100} PB` + } else if(bytes >= 1099511627776){ // Terabytes + return `${Math.round(bytes / 1099511627776 * 100) / 100} TB` + } else if(bytes >= 1073741824){ // Gigabytes + return `${Math.round(bytes / 1073741824 * 100) / 100} GB` + } else if(bytes >= 1048576){ // Megabytes + return `${Math.round(bytes / 1048576 * 100) / 100} MB` + } else if(bytes >= 1024){ // Kilobytes + return `${Math.round(bytes / 1024 * 100) / 100} KB` + } else { // Bytes + return `${bytes} B` + } +}