I'm trying to calculate the CPU usage on the computer running my nodejs app but for some reason the output is a lot higher than what my system monitor on ubuntu is showing me. Here is my code:
const cores = _.map(os.cpus(), 'times')
const free = _.sumBy(cores, 'idle')
const total = _.sumBy(cores, c => _.sum(_.values(c)))
const usage = free * 100 / total
console.log(usage)
This outputs ~89% whereas the system monitor shows that all of my CPUs are under 30%. I also tried calcualting it on just one core like this:
console.log(cores[1].idle / _.sum(_.values(cores[1])))
But this still showed a similar number that was way too high. Am I doing something wrong?