Convert the output of os.cpus() in Node.js to percentage

后端 未结 8 1626
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 11:27

Is there a way to convert the os.cpus() info to percentage? Just like the output of iostat (on the CPU section).

My code:

var os = require(\'os\');
c         


        
8条回答
  •  借酒劲吻你
    2020-12-08 11:36

    i'm using this code:

    var cpu_used = function(){
    var cpu = os.cpus();
    
    var counter = 0;
    var total=0;
    
    var free=0;
    var sys=0;
    var user=0;
    
    for (var i = 0; i

提交回复
热议问题