Obtain percentage of CPU usage in javascript

2

I'm doing an application in node to get the percentage of use of the processor, I tried to get it from the module times os, but it differs a lot from what it shows in the task manager.

I have tried with this: link

EDIT: In the end I decided to use this module link to execute the command wmic cpu get loadpercentage and thus get the percentage

    
asked by Isai Alvarez 27.10.2016 в 19:46
source

1 answer

0

I can suggest you use pidusage: link Apparently it is more complicated than it seems what you are looking for.

Example of documentation:

var pusage = require('pidusage')

pusage.stat(process.pid, function(err, stat) {

    expect(err).to.be.null
    expect(stat).to.be.an('object')
    expect(stat).to.have.property('cpu')
    expect(stat).to.have.property('memory')

    console.log('Pcpu: %s', stat.cpu)
    console.log('Mem: %s', stat.memory) //those are bytes

})

// Unmonitor process
pusage.unmonitor(process.pid);
    
answered by 28.10.2016 / 17:53
source