Guest User

Untitled

a guest
Dec 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. var os = require("os");
  2. var exec = require('child_process').exec;
  3.  
  4. function sysLog(){
  5. //exec('clear', sysLog);
  6. var cpus = os.cpus();
  7.  
  8. for(var i = 0, len = cpus.length; i < len; i++) {
  9. var cpu = cpus[i], total = 0, processTotal = 0, strPercent = '';
  10.  
  11. console.log("CPU %s:", i);
  12. console.log("\t",'user',cpu.times.user,'|nice',cpu.times.nice,'|sys',cpu.times.sys,'|idle',cpu.times.idle,'|irq',cpu.times.irq);
  13.  
  14. for(type in cpu.times){
  15. total += cpu.times[type];
  16. }
  17.  
  18. for(type in cpu.times){
  19. var percent = Math.round(100 * cpu.times[type] / total);
  20. strPercent += type + ' ' + percent + '%|';
  21. if(type != 'idle'){
  22. processTotal += percent;
  23. }
  24. }
  25. console.log("\t",strPercent)
  26. console.log("\t",'T0TAL PROCESSOR: ',total);
  27. console.log("\t",'TOTAL: ',processTotal);
  28. }
  29. }
  30.  
  31. var interval = setInterval(sysLog, 1000);
  32.  
  33. setTimeout(function(){
  34. clearInterval(interval);
  35. },100000);
Add Comment
Please, Sign In to add comment