Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var os = require("os");
- var exec = require('child_process').exec;
- function sysLog(){
- //exec('clear', sysLog);
- var cpus = os.cpus();
- for(var i = 0, len = cpus.length; i < len; i++) {
- var cpu = cpus[i], total = 0, processTotal = 0, strPercent = '';
- console.log("CPU %s:", i);
- console.log("\t",'user',cpu.times.user,'|nice',cpu.times.nice,'|sys',cpu.times.sys,'|idle',cpu.times.idle,'|irq',cpu.times.irq);
- for(type in cpu.times){
- total += cpu.times[type];
- }
- for(type in cpu.times){
- var percent = Math.round(100 * cpu.times[type] / total);
- strPercent += type + ' ' + percent + '%|';
- if(type != 'idle'){
- processTotal += percent;
- }
- }
- console.log("\t",strPercent)
- console.log("\t",'T0TAL PROCESSOR: ',total);
- console.log("\t",'TOTAL: ',processTotal);
- }
- }
- var interval = setInterval(sysLog, 1000);
- setTimeout(function(){
- clearInterval(interval);
- },100000);
Add Comment
Please, Sign In to add comment