feat: human readable uptime

This commit is contained in:
Barış Soner Uşaklı
2020-11-21 23:34:12 -05:00
parent d1cb5d4813
commit 672d4da078
2 changed files with 13 additions and 1 deletions

View File

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

View File

@@ -41,7 +41,7 @@
<td>{info.process.cpuUsage.user} / {info.process.cpuUsage.system}</td>
<td>{info.process.memoryUsage.humanReadable} mb / {info.os.freemem} mb</td>
<td>{info.os.load}</td>
<td>{info.process.uptime}</td>
<td>{info.process.uptimeHumanReadable}</td>
</tr>
<!-- END info -->
</tbody>