Skip to content

Instantly share code, notes, and snippets.

@remixer-dec
Last active January 2, 2019 23:41
Show Gist options
  • Save remixer-dec/a7f226501c407142d55862283ff45bda to your computer and use it in GitHub Desktop.
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
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