Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getStats() {
// core stats
const stats: any = {
memory: {
total: (((os.totalmem() / 1024) / 1024) / 1024).toFixed(2),
used: ((((os.totalmem() - os.freemem()) / 1024) / 1024) / 1024).toFixed(2),
free: (((os.freemem() / 1024) / 1024) / 1024).toFixed(2)
}
};
stats.cpu = (os.platform() === 'win32') ? null : (os.loadavg()[0] * 100 / os.cpus().length).toFixed(2);
// server uptime
const uptime: any = {
delta: Math.floor(os.uptime())
};
uptime.days = Math.floor(uptime.delta / 86400);
uptime.delta -= uptime.days * 86400;
uptime.hours = Math.floor(uptime.delta / 3600) % 24;
uptime.delta -= uptime.hours * 3600;
uptime.minutes = Math.floor(uptime.delta / 60) % 60;
stats.uptime = uptime;
// cpu temp
let temp = null;
if (hb.temperatureFile) {
try {
temp = fs.readFileSync(hb.temperatureFile);
temp = ((temp / 1000).toPrecision(3));
private _getMetricResult(sensorId: string): number {
const metricIndex = this._sensorsArray.findIndex(s => s.objectId === sensorId);
switch (metricIndex) {
case 0:
// The load average is a UNIX-specific concept with no real equivalent on Windows platforms.
// On Windows, the return value is always [0, 0, 0].
return Math.round(osType().startsWith("Windows") ? Math.random() * 100 : loadavg()[0] * 100);
case 1:
return freemem();
case 2:
return uptime();
default:
throw new TypeError("There are only three metrics. Got index " + metricIndex);
}
}
}
// New block.
this.newBlock = new Block();
// Secret
this.secret = 'Block0';
// is success
this._success = false;
// Merkle tree
this._tree = [];
// Jiffy and uptime
this.jiffies = 0;
this.startUptime = os.uptime();
}
bytes = require('bytes'),
colors = require('./art/colors.js'),
elapsed = require('./lib/elapsed.js'),
deDict = require('./lib/de-dict.json'),
wmDict = require('./lib/wm-dict.json');
function color(used, total) {
var quadrant = Math.min(Math.ceil( Math.floor(used / total * 100) / 33), 3),
cols = [ colors.greenB, colors.greenB, colors.yellowB, colors.redB ];
return cols[quadrant] + bytes(used) + colors.clear + ' / ' + bytes(total);
}
var result = {
user: { key: 'User', value: process.env.USER || process.env.USERNAME },
hostname: { key: 'Hostname', value: os.hostname() },
uptime: { key: 'Uptime', value: elapsed(os.uptime()) },
cpu: { key: 'CPU', value: os.cpus()[0].model.replace('Intel(R) Core(TM) ', 'Intel ').replace('Intel(R) Core(TM)2 ', 'Intel ') },
ram: { key: 'RAM', value: color( os.totalmem() - os.freemem(), os.totalmem()) },
sh: { key: 'Shell', value: process.env.SHELL && process.env.SHELL.split('/').pop() },
term: { key: 'Terminal', value: process.env.TERM && process.env.TERM.split('/').pop() }
},
processes,
distro;
var tasks = [
function(done) {
switch(distro) {
case 'Debian':
case 'Ubuntu':
case 'Kubuntu':
case 'Fedora':
case 'CrunchBang':
getUptime() {
return formatUptime(os.uptime())
}
app.get("/osInfo", (req, res) => {
var os = require("os");
var output = {};
output.tmpdir = os.tmpdir();
output.endianness = os.endianness();
output.hostname = os.hostname();
output.type = os.type();
output.platform = os.platform();
output.arch = os.arch();
output.release = os.release();
output.uptime = os.uptime();
output.loadavg = os.loadavg();
output.totalmem = os.totalmem();
output.freemem = os.freemem();
output.cpus = os.cpus();
output.networkInfraces = os.networkInterfaces();
var result = JSON.stringify(output);
res.type("application/json").status(200).send(result);
});
exception.getOsInfo = function () {
return {
loadavg: os.loadavg(),
uptime: os.uptime()
};
};
},
memory: {
rss: bytesToSize(usage.rss, 3),
heapTotal: bytesToSize(usage.heapTotal, 3),
heapUsed: bytesToSize(usage.heapUsed, 3)
},
system: {
platform: os.platform(),
release: os.release(),
hostname: os.hostname(),
memory: {
free: bytesToSize(os.freemem(), 3),
total: bytesToSize(os.totalmem(), 3)
},
load: os.loadavg(),
uptime: os.uptime(),
uptimeFormatted: secondsToString(os.uptime())
},
routes: health
};
help.sendBackJSON(200, res, next)(null, data);
});
platform: process.platform,
version: process.version,
installPrefix: process.installPrefix,
title: process.title,
execPath: process.execPath,
argv: process.argv,
env: process.env,
cwd: process.cwd(),
gid: process.getgid ? process.getgid() : 0,
uid: process.getuid ? process.getuid() : 0,
pid: process.pid,
umask: process.umask(),
hostname: OS.hostname(),
type: OS.type(),
release: OS.release(),
osUptime: OS.uptime(),
loadavg: OS.loadavg(),
freemem: OS.freemem(),
totalmem: OS.totalmem(),
cpus: OS.cpus()
}, process.memoryUsage());
if (process.uptime) {attrs.uptime = process.uptime();}
if (process.versions) {attrs.versions = process.versions;}
if (process.arch) {attrs.arch = process.arch;}
t.set(attrs);
}
});
function getSystemStatus() {
return {
hostname: os.hostname(),
port: config.port,
platform: os.platform(),
arch: os.arch(),
release: os.release(),
systemTime: new Date(),
uptime: os.uptime()
};
}