|
|
@ -11,6 +11,8 @@ const rooms = require('../../socket.io/admin/rooms');
|
|
|
|
const infoController = module.exports;
|
|
|
|
const infoController = module.exports;
|
|
|
|
|
|
|
|
|
|
|
|
let info = {};
|
|
|
|
let info = {};
|
|
|
|
|
|
|
|
let previousUsage = process.cpuUsage();
|
|
|
|
|
|
|
|
let usageStartDate = Date.now();
|
|
|
|
|
|
|
|
|
|
|
|
infoController.get = function (req, res) {
|
|
|
|
infoController.get = function (req, res) {
|
|
|
|
info = {};
|
|
|
|
info = {};
|
|
|
@ -69,7 +71,7 @@ async function getNodeInfo() {
|
|
|
|
version: process.version,
|
|
|
|
version: process.version,
|
|
|
|
memoryUsage: process.memoryUsage(),
|
|
|
|
memoryUsage: process.memoryUsage(),
|
|
|
|
uptime: process.uptime(),
|
|
|
|
uptime: process.uptime(),
|
|
|
|
cpuUsage: process.cpuUsage(),
|
|
|
|
cpuUsage: getCpuUsage(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
os: {
|
|
|
|
os: {
|
|
|
|
hostname: os.hostname(),
|
|
|
|
hostname: os.hostname(),
|
|
|
@ -88,14 +90,12 @@ async function getNodeInfo() {
|
|
|
|
jobsDisabled: nconf.get('jobsDisabled'),
|
|
|
|
jobsDisabled: nconf.get('jobsDisabled'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
data.process.cpuUsage.user /= 1000000;
|
|
|
|
|
|
|
|
data.process.cpuUsage.user = data.process.cpuUsage.user.toFixed(2);
|
|
|
|
data.process.memoryUsage.humanReadable = (data.process.memoryUsage.rss / (1024 * 1024 * 1024)).toFixed(3);
|
|
|
|
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.process.uptimeHumanReadable = humanReadableUptime(data.process.uptime);
|
|
|
|
data.os.freemem = (data.os.freemem / 1000000).toFixed(2);
|
|
|
|
data.os.freemem = (data.os.freemem / (1024 * 1024 * 1024)).toFixed(2);
|
|
|
|
data.os.totalmem = (data.os.totalmem / 1000000).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([
|
|
|
|
const [stats, gitInfo] = await Promise.all([
|
|
|
|
rooms.getLocalStats(),
|
|
|
|
rooms.getLocalStats(),
|
|
|
|
getGitInfo(),
|
|
|
|
getGitInfo(),
|
|
|
@ -105,6 +105,16 @@ async function getNodeInfo() {
|
|
|
|
return data;
|
|
|
|
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) {
|
|
|
|
function humanReadableUptime(seconds) {
|
|
|
|
if (seconds < 60) {
|
|
|
|
if (seconds < 60) {
|
|
|
|
return `${Math.floor(seconds)}s`;
|
|
|
|
return `${Math.floor(seconds)}s`;
|
|
|
|