tdudzik

Process Monitoring

Mar 15th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const cmd = require('node-cmd');
  2. const argv = require('yargs')
  3.     .option('pid', { alias: 'p' })
  4.     .option('interval', { alias: 'i', default: 3000 })
  5.     .demandOption(['pid'])
  6.     .argv;
  7.  
  8. setInterval(() => {
  9.     cmd.get("top -p " + argv.port + " -b -d 1 | head -n 8 | tail -1 | awk '{print $9\" \"$10}'", (data) => {
  10.         const result = data.split(" ");        
  11.  
  12.         const cpu = result[0];
  13.         const memory = result[1];
  14.  
  15.         console.log("CPU:", cpu, "Memory:", memory);
  16.     });
  17. }, argv.interval);
Advertisement
Add Comment
Please, Sign In to add comment