75 lines
1.3 KiB
JavaScript
75 lines
1.3 KiB
JavaScript
|
const logger = require('./logger.js');
|
||
|
const os = require('os');
|
||
|
|
||
|
function getHostname() {
|
||
|
return os.hostname();
|
||
|
}
|
||
|
|
||
|
function getUptime() {
|
||
|
return os.uptime();
|
||
|
}
|
||
|
|
||
|
function getLoadAverage(index) {
|
||
|
var loadAverage = os.loadavg();
|
||
|
if (index <= loadAverage.length) {
|
||
|
return os[index];
|
||
|
}
|
||
|
return os.loadavg();
|
||
|
}
|
||
|
|
||
|
function getArchitecture() {
|
||
|
return os.arch;
|
||
|
}
|
||
|
|
||
|
function getOperatingSystem() {
|
||
|
return os.release();
|
||
|
}
|
||
|
|
||
|
function getPlatform() {
|
||
|
return os.platform();
|
||
|
}
|
||
|
|
||
|
function getKernelVersion() {
|
||
|
return os.version();
|
||
|
}
|
||
|
|
||
|
function getCpuInfo() {
|
||
|
return os.cpus();
|
||
|
}
|
||
|
|
||
|
function getMemoryInfo() {
|
||
|
var free = os.freemem();
|
||
|
var total = os.totalmem();
|
||
|
return {
|
||
|
total: total,
|
||
|
free: free,
|
||
|
used: total - free
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getHostInfo() {
|
||
|
return {
|
||
|
hostname: getHostname(),
|
||
|
uptime: getUptime(),
|
||
|
load: getLoadAverage(),
|
||
|
arch: getArchitecture(),
|
||
|
os: getOperatingSystem(),
|
||
|
platform: getPlatform(),
|
||
|
kernel: getKernelVersion(),
|
||
|
cpu: getCpuInfo(),
|
||
|
memory: getMemoryInfo()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
getHostname,
|
||
|
getUptime,
|
||
|
getLoadAverage,
|
||
|
getArchitecture,
|
||
|
getOperatingSystem,
|
||
|
getPlatform,
|
||
|
getKernelVersion,
|
||
|
getCpuInfo,
|
||
|
getMemoryInfo,
|
||
|
getHostInfo
|
||
|
}
|