diff --git a/public/language/en-GB/admin/development/info.json b/public/language/en-GB/admin/development/info.json index 1003af1a5f..11202d9c3a 100644 --- a/public/language/en-GB/admin/development/info.json +++ b/public/language/en-GB/admin/development/info.json @@ -8,7 +8,11 @@ "nodejs": "nodejs", "online": "online", "git": "git", - "memory": "memory", + "process-memory": "process memory", + "system-memory": "system memory", + "used-memory-process": "Used memory by process", + "used-memory-os": "Used system memory", + "total-memory-os": "Total system memory", "load": "system load", "cpu-usage": "cpu usage", "uptime": "uptime", diff --git a/src/controllers/admin/info.js b/src/controllers/admin/info.js index 60558f2ad6..efd126579e 100644 --- a/src/controllers/admin/info.js +++ b/src/controllers/admin/info.js @@ -11,6 +11,8 @@ const rooms = require('../../socket.io/admin/rooms'); const infoController = module.exports; let info = {}; +let previousUsage = process.cpuUsage(); +let usageStartDate = Date.now(); infoController.get = function (req, res) { info = {}; @@ -69,7 +71,7 @@ async function getNodeInfo() { version: process.version, memoryUsage: process.memoryUsage(), uptime: process.uptime(), - cpuUsage: process.cpuUsage(), + cpuUsage: getCpuUsage(), }, os: { hostname: os.hostname(), @@ -88,14 +90,12 @@ async function getNodeInfo() { jobsDisabled: nconf.get('jobsDisabled'), }, }; - data.process.cpuUsage.user /= 1000000; - data.process.cpuUsage.user = data.process.cpuUsage.user.toFixed(2); - data.process.cpuUsage.system /= 1000000; - data.process.cpuUsage.system = data.process.cpuUsage.system.toFixed(2); - data.process.memoryUsage.humanReadable = (data.process.memoryUsage.rss / (1024 * 1024)).toFixed(2); + + data.process.memoryUsage.humanReadable = (data.process.memoryUsage.rss / (1024 * 1024 * 1024)).toFixed(3); data.process.uptimeHumanReadable = humanReadableUptime(data.process.uptime); - data.os.freemem = (data.os.freemem / 1000000).toFixed(2); - data.os.totalmem = (data.os.totalmem / 1000000).toFixed(2); + data.os.freemem = (data.os.freemem / (1024 * 1024 * 1024)).toFixed(2); + data.os.totalmem = (data.os.totalmem / (1024 * 1024 * 1024)).toFixed(2); + data.os.usedmem = (data.os.totalmem - data.os.freemem).toFixed(2); const [stats, gitInfo] = await Promise.all([ rooms.getLocalStats(), getGitInfo(), @@ -105,6 +105,16 @@ async function getNodeInfo() { return data; } +function getCpuUsage() { + const newUsage = process.cpuUsage(); + const diff = (newUsage.user + newUsage.system) - (previousUsage.user + previousUsage.system); + const now = Date.now(); + const result = diff / ((now - usageStartDate) * 1000) * 100; + previousUsage = newUsage; + usageStartDate = now; + return result.toFixed(2); +} + function humanReadableUptime(seconds) { if (seconds < 60) { return `${Math.floor(seconds)}s`; diff --git a/src/views/admin/development/info.tpl b/src/views/admin/development/info.tpl index 604e13bfb7..bb113ab0d9 100644 --- a/src/views/admin/development/info.tpl +++ b/src/views/admin/development/info.tpl @@ -17,7 +17,8 @@