mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: human readable uptime
This commit is contained in:
@@ -93,6 +93,7 @@ async function getNodeInfo() {
|
|||||||
data.process.cpuUsage.system /= 1000000;
|
data.process.cpuUsage.system /= 1000000;
|
||||||
data.process.cpuUsage.system = data.process.cpuUsage.system.toFixed(2);
|
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)).toFixed(2);
|
||||||
|
data.process.uptimeHumanReadable = humanReadableUptime(data.process.uptime);
|
||||||
data.os.freemem = (data.os.freemem / 1000000).toFixed(2);
|
data.os.freemem = (data.os.freemem / 1000000).toFixed(2);
|
||||||
data.os.totalmem = (data.os.totalmem / 1000000).toFixed(2);
|
data.os.totalmem = (data.os.totalmem / 1000000).toFixed(2);
|
||||||
const [stats, gitInfo] = await Promise.all([
|
const [stats, gitInfo] = await Promise.all([
|
||||||
@@ -104,6 +105,17 @@ async function getNodeInfo() {
|
|||||||
return data;
|
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() {
|
async function getGitInfo() {
|
||||||
function get(cmd, callback) {
|
function get(cmd, callback) {
|
||||||
exec(cmd, function (err, stdout) {
|
exec(cmd, function (err, stdout) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<td>{info.process.cpuUsage.user} / {info.process.cpuUsage.system}</td>
|
<td>{info.process.cpuUsage.user} / {info.process.cpuUsage.system}</td>
|
||||||
<td>{info.process.memoryUsage.humanReadable} mb / {info.os.freemem} mb</td>
|
<td>{info.process.memoryUsage.humanReadable} mb / {info.os.freemem} mb</td>
|
||||||
<td>{info.os.load}</td>
|
<td>{info.os.load}</td>
|
||||||
<td>{info.process.uptime}</td>
|
<td>{info.process.uptimeHumanReadable}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- END info -->
|
<!-- END info -->
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user