$ cnpm install psaux
Process status in Node.js as you've always wanted
Promise oriented and lightweight Javascript utility for getting info about the processes runing in your machine. It is designed to give you a friendly api for filter within all of them.
$ npm install psaux --save
# Usage
Display the user, pid, cpu and mem of all the running processes:
const psaux = require('psaux');
psaux().then(list => {
list.forEach(ps => {
console.log(ps.user, ps.pid, ps.cpu, ps.mem);
});
});
Find a concrete process using his pid
psaux().then(list => {
let chrome = list.query({pid: 12345});
console.log('Google chrome is using ' + chrome.cpu + '% of CPU and ' + chrome.mem + '% of memory');
});
Display inefficient processes started from the root user.
psaux().then(list => {
let inefficient = list.query({
user: 'root',
mem: '>5'
});
console.log('Processes started by root and using more that 5% of memory');
});
Search for a process containing the passed string (very useful if you don't know the pid)
psaux().then(list => {
let chrome = list.query({command: '~chrome'});
if (chrome) {
console.log('Chrome process found!', chrome);
}
});
You can filter by every property of the returned objects using the query method. Also you can create complex filters if needed:
list.query({
user: 'john',
mem: '>2 <10',
vsz: '>4000000',
command: '~Sublime Text'
});
> Greater than: >5< Lower than: <5~ Contains: ~ChromeThe properties you can access are basically the same listed in the ps command:
# Supported platforms
The module currently supports Mac OS, Linux and Windows.
Copyright 2013 - present © cnpmjs.org | Home |