Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
api.get('/cpu/temp', function(req, res) { // CPU Temperature in C (cpu/temp)
si.cpuTemperature()
.then(data => res.send(data.main.toString()))
.catch(error => res.status(404).send(siError))
})
api.get('/cpu/usage', function(req, res) { // CPU Usage % (cpu/usage)
let intervalId = setInterval(() => {
si.currentLoad().then(data => {
this.setState({ load: data });
});
si.cpuCurrentspeed().then(data => {
this.setState({ speed: data });
});
si.cpuTemperature()
.then(data => {
this.setState({ temp: data });
})
.catch(error => console.error(error));
}, 1000);
this.setState({ intervalId: intervalId });
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) {
console.warn(
'Cannot pull temperature data. On Linux, make sure `sensors` is available (package: lm-sensors). For OS X, install osx-temperature-sensor. Some CPUs are not supported on Windows.'
);
tempFlag = true;
}
}
async function readTemp() {
const temp = await si.cpuTemperature();
return { main: temp.main, cores: temp.cores };
}
export async function dynamicInfo(): Promise {
const osData = {
hostname: os.hostname(),
uptime: os.uptime(),
freemem: os.freemem(),
totalmem: os.totalmem(),
cpus: os.cpus(),
loadavg: os.loadavg()
}
const promises = [
si.battery(),
si.graphics(),
si.osInfo(),
si.fsSize(),
si.cpuTemperature()
];
const [battery, graphics, osInfo, fsSize, cpuTemp] = await Promise.all(promises);
return {
...osData,
battery,
graphics,
osInfo,
fsSize,
cpuTemp
};
}
si.cpuCurrentspeed(function(speed) {
si.cpuTemperature(function(temp) {
si.currentLoad(function(load) {
SYSINFO.cpu = {
speed,
temp,
load
}
})
})
})
}