Last active
January 2, 2019 23:41
-
-
Save remixer-dec/a7f226501c407142d55862283ff45bda to your computer and use it in GitHub Desktop.
NodeJS script to detect and log CPU usage per process (for example when PC is in lockscreen or in pseudo-sleep-mode) | run cmd as admin to get all processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ps = require('current-processes') | |
const _ = require('lodash') | |
const fs = require('fs') | |
function saveData(){ | |
ps.get(function(err, processes) { | |
for(let prc of processes){ | |
delete prc.mem | |
} | |
let sorted = _.sortBy(processes, 'cpu') | |
let top5 = sorted.reverse().splice(0, 5) | |
let name = new Date().toTimeString().split(" ")[0].replace(/\:/ig,'_')+".json" | |
console.log(name); | |
fs.writeFileSync(name,JSON.stringify(top5)) | |
}); | |
} | |
setInterval(saveData,30000) | |
//SETUP: | |
//npm i curent-processes | |
//npm i lodash | |
//node cpu_usage_logger.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment