Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function legacyJsonOutput(results: BenchmarkResult[]):
Promise {
// TODO Add git info.
const battery = await systeminformation.battery();
const cpu = await systeminformation.cpu();
const currentLoad = await systeminformation.currentLoad();
const memory = await systeminformation.mem();
return {
benchmarks: results,
datetime: new Date().toISOString(),
system: {
cpu: {
manufacturer: cpu.manufacturer,
model: cpu.model,
family: cpu.family,
speed: cpu.speed,
cores: cpu.cores,
},
load: {
average: currentLoad.avgload,
current: currentLoad.currentload,
},
api.get('/cpu/usage', function(req, res) { // CPU Usage % (cpu/usage)
si.currentLoad()
.then(data => res.send(data.currentload.toString()))
.catch(error => res.status(404).send(siError))
})
function updateSi() { // Gather params
var sysInfo = {cpu:0,mem:0,temp:0};
si.currentLoad(function(data) {
sysInfo.cpu = data.currentload;
si.mem(function(data) {
sysInfo.mem = (data.active/data.total)*100;
si.cpuTemperature(function(data) {
sysInfo.temp = data.main;
systemMonitor.system.cpu = sysInfo.cpu.toPrecision(3).toString() + ' %';
systemMonitor.system.mem = sysInfo.mem.toPrecision(2).toString() + ' %';
systemMonitor.system.temp = sysInfo.temp.toPrecision(3).toString() + ' °C';
systemMonitor.system.ip = ip.address();
});
});
});
setInterval(() => {
try {
si.currentLoad(val => {
this.cpuValue = val.currentload.toFixed(0)
cpuBar.animate(this.cpuValue / 100)
})
} catch(err) {
}
}, 1000)
}
mounted() {
si.currentLoad(val => {
let cpuCount = val.cpus.length
for (var i = 0; i < cpuCount; i++)
this.cpuValues.push([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
])
let cpuChart = new Chartkick.LineChart('cpus-chart', this.cpuData, {
colors: ['#2ecc71', '#e74c3c', '#3498db', '#f1c40f', '#9b59b6', '#34495e',
'#1abc9c', '#e67e22', '#46f0f0', '#f032e6', '#fabebe', '#008080',
'#e6beff', '#aa6e28', '#d2f53c', '#800000', '#aaffc3', '#808000',
'#000080', '#808080'],
legend: true,
min: 0,
max: 100,
points: false
getCpuLoad() {
cpuLoad().then(({ currentload }) =>
this.setState({
cpuLoad: leftPad(currentload.toFixed(2), 2, 0)
})
)
}
si.cpuTemperature(function(temp) {
si.currentLoad(function(load) {
SYSINFO.cpu = {
speed,
temp,
load
}
})
})
})
const poll = async () => {
cpuLoad = await SI.currentLoad();
mem = await SI.mem();
disk = await SI.fsSize();
processes = await SI.processes();
network = await SI.networkStats();
try {
cpuTemp = await SI.cpuTemperature();
if (!cpuTemp.cores.length) {
throw new Error('Cannot monitor CPU temperature');
}
} catch (e) {
cpuTemp = {
main: 0,
cores: Array(cpu.cores).fill(0),
max: 0
};
if (!tempFlag) {