From 672d4da078d2d066602be8a82d696d208e5b60bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 21 Nov 2020 23:34:12 -0500 Subject: [PATCH] feat: human readable uptime --- src/controllers/admin/info.js | 12 ++++++++++++ src/views/admin/development/info.tpl | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/controllers/admin/info.js b/src/controllers/admin/info.js index 36dec3a0ef..9919deb8cc 100644 --- a/src/controllers/admin/info.js +++ b/src/controllers/admin/info.js @@ -93,6 +93,7 @@ async function getNodeInfo() { 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.uptimeHumanReadable = humanReadableUptime(data.process.uptime); data.os.freemem = (data.os.freemem / 1000000).toFixed(2); data.os.totalmem = (data.os.totalmem / 1000000).toFixed(2); const [stats, gitInfo] = await Promise.all([ @@ -104,6 +105,17 @@ async function getNodeInfo() { return data; } +function humanReadableUptime(seconds) { + if (seconds < 60) { + return Math.floor(seconds) + 's'; + } else if (seconds < 3600) { + return Math.floor(seconds / 60) + 'm'; + } else if (seconds < 3600 * 24) { + return Math.floor(seconds / (60 * 60)) + 'h'; + } + return Math.floor(seconds / (60 * 60 * 24)) + 'd'; +} + async function getGitInfo() { function get(cmd, callback) { exec(cmd, function (err, stdout) { diff --git a/src/views/admin/development/info.tpl b/src/views/admin/development/info.tpl index 5d4df86bd5..604e13bfb7 100644 --- a/src/views/admin/development/info.tpl +++ b/src/views/admin/development/info.tpl @@ -41,7 +41,7 @@ {info.process.cpuUsage.user} / {info.process.cpuUsage.system} {info.process.memoryUsage.humanReadable} mb / {info.os.freemem} mb {info.os.load} - {info.process.uptime} + {info.process.uptimeHumanReadable}