Add memory to serverinfo

This commit is contained in:
7cc5c4f330d47060 2024-09-05 15:50:11 -04:00
parent 946698b705
commit e243eb02f7
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
3 changed files with 35 additions and 1 deletions

View file

@ -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)

View file

@ -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",

15
util/memoryconvert.js Normal file
View file

@ -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`
}
}