Add memory to serverinfo
This commit is contained in:
parent
946698b705
commit
e243eb02f7
3 changed files with 35 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const cp = require('child_process')
|
const cp = require('child_process')
|
||||||
const { getMessage, formatTime } = require('../util/lang.js')
|
const { getMessage, formatTime } = require('../util/lang.js')
|
||||||
|
const memoryconvert = require('../util/memoryconvert.js')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const botVersion = require('../util/version.js')
|
const botVersion = require('../util/version.js')
|
||||||
const version = require('../version.json')
|
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
|
// Username and UID
|
||||||
displayInfo('command.about.serverInfo.osUsername', () => {
|
displayInfo('command.about.serverInfo.osUsername', () => {
|
||||||
return `${os.userInfo().username} (${os.userInfo().uid})`
|
return `${os.userInfo().username} (${os.userInfo().uid})`
|
||||||
|
@ -179,7 +195,7 @@ const aboutServer = function (c) {
|
||||||
displayInfo('command.about.serverInfo.runTime', () => {
|
displayInfo('command.about.serverInfo.runTime', () => {
|
||||||
return formatTime(process.uptime() * 1000, c.lang)
|
return formatTime(process.uptime() * 1000, c.lang)
|
||||||
})
|
})
|
||||||
|
|
||||||
// System uptime
|
// System uptime
|
||||||
displayInfo('command.about.serverInfo.upTime', () => {
|
displayInfo('command.about.serverInfo.upTime', () => {
|
||||||
return formatTime(os.uptime() * 1000, c.lang)
|
return formatTime(os.uptime() * 1000, c.lang)
|
||||||
|
|
|
@ -98,6 +98,9 @@
|
||||||
"command.about.serverInfo.kernelVer": "Kernel version",
|
"command.about.serverInfo.kernelVer": "Kernel version",
|
||||||
"command.about.serverInfo.processor": "CPU",
|
"command.about.serverInfo.processor": "CPU",
|
||||||
"command.about.serverInfo.arch": "Architecture",
|
"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.osUsername": "Username",
|
||||||
"command.about.serverInfo.hostName": "Hostname",
|
"command.about.serverInfo.hostName": "Hostname",
|
||||||
"command.about.serverInfo.workingDir": "Working directory",
|
"command.about.serverInfo.workingDir": "Working directory",
|
||||||
|
|
15
util/memoryconvert.js
Normal file
15
util/memoryconvert.js
Normal 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`
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue