GithubHelp home page GithubHelp logo

ykankaya / psaux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zzarcon/psaux

0.0 1.0 0.0 18 KB

:package: Process status in Node.js as you've always wanted

License: MIT License

JavaScript 100.00%

psaux's Introduction

psaux Build Status npm version Dependency Status npm license

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.

Install

$ 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);
  }
}); 

Filters

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: ~Chrome

Properties

The properties you can access are basically the same listed in the ps command:

  • user: user owning the process
  • pid: process ID
  • cpu: It is the CPU time used divided by the time the process has been running.
  • mem: ratio of the process’s resident set size to the physical memory on the machine
  • vsz: virtual memory usage of entire process (in KiB)
  • rss: resident set size, the non-swapped physical memory that a task has used (in KiB)
  • tt: controlling tty (terminal)
  • stat: multi-character process state
  • started: starting time or date of the process
  • time: cumulative CPU time
  • command: command with all its arguments

# Supported platforms

The module currently supports Mac OS, Linux and Windows.

psaux's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.