Giter VIP home page Giter VIP logo

event-loop-inspector's Introduction

Event loop inspector


npm version

Purpose

Dump event loop data. Useful to known which processes are running and potentially block your application. Can be used for real time monitoring also.

It basically call core NodeJs functions _getActiveHandles and _getActiveRequests to inspect event loop's state.

No dependency.

Compatibility

Supported and tested : >= 4.x Not supported but should work : 0.12.x

Version Supported Tested
9.x yes yes
8.x yes yes
7.x yes yes
6.x yes yes
4.x yes yes
0.12.x no yes( manually)
> 0.12.x no no

Installation

$ npm install event-loop-inspector --save

Usage

Basic usage

const inspector = require('event-loop-inspector')();
const dump = inspector.dump();

console.log(dump);

Output

{
  handles:
      {
        setTimeout:
            [{
              type: 'setTimeout',
              startAfter: 311,
              name: 'anonymous',
              msecs: 2000
            }],
        Server:
            [{
              type: 'Server',
              address: '::',
              port: 8000,
              listeners: [{name: 'connectionListener'}]
            }],
        Socket:
            [{
              type: 'Socket',
              localAddress: '127.0.0.1',
              localPort: 45014,
              remoteAddress: '127.0.0.1',
              remotePort: 8000,
              remoteFamily: 'IPv4',
              method: 'GET',
              path: '/toto',
              headers: {host: '127.0.0.1:8000'},
              listeners: []
            }]
      },
  requests:
      {
        TCPConnectWrap:
            [{
              type: 'TCPConnectWrap',
              address: 'xxx.xxx.xxx.xxx',
              port: xxxx,
              localAddress: 'xxx.xxx.xxx.xxx',
              localPort: xxxx
            }]
      },
  setImmediates:
      [
        {type: 'setImmediate', name: 'setImmediateTest2'},
        {type: 'setImmediate', name: 'anonymous'}
      ],
  nextTicks:
      [
        {type: 'nextTick', name: 'afterWrite'},
        {type: 'nextTick', name: 'anonymous'}
      ]
}

Inspect more functions

By default setImmediates and process.nextTick can't be retrieved with functions _getActiveHandles/_getActiveRequests. If you want to allow event-loop-inspector to wrap some core functions, instantiate inspector with first argument set as true.

const inspector = require('event-loop-inspector')(true);
const dump = inspector.dump();

console.log(dump);

Functions that can be wrapped :

  • process.nextTick
  • setImmediate

/!\ Enabling this option may lower performance of the functions involved.

Test

$ npm test

To generate coverage :

$ npm run test-coverage

Coverage report can be found in coverage/.

event-loop-inspector's People

Contributors

apla avatar ejdaly avatar unitech avatar wallet77 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

event-loop-inspector's Issues

Install fails for global setup

Hey!

Trying out pm2 plus and seems to be something strange when setting up?

I've installed with -g and ran pm2 plus key key and it fails to install event-loop-inspector.

The servers show up and stuff like that so not really sure if it worked as intended anyway?

Here's the log for it:

centos@ip-172-31-37-172 ~]$ pm2 plus key key
[PM2 I/O] Using: Public key: key | Private key: key | Machine name: ip-172-31-37-172.eu-central-1.compute.internal-6454
[+] PM2+ activated!
[PM2][Module] Installing module pm2-logrotate
[PM2][Module] Calling [NPM] to install pm2-logrotate ...
[PM2][Module] Installing module pm2-server-monit
[PM2][Module] Calling [NPM] to install pm2-server-monit ...
[PM2][Module] Installing module event-loop-inspector
[PM2][Module] Calling [NPM] to install event-loop-inspector ...
+ [email protected]
added 36 packages from 45 contributors and audited 45 packages in 4.95s
found 0 vulnerabilities

[PM2][Module] Module downloadedadata: sill resolveWithNewModule [email protected] checking installable status
[PM2][WARN] Applications pm2-server-monit not running, [email protected] checking installable status
npm ERR! path /usr/lib/node_modules/pm2/node_modules/event-loop-inspector
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules/pm2/node_modules/event-loop-inspector'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/lib/node_modules/pm2/node_modules/event-loop-inspector']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/lib/node_modules/pm2/node_modules/event-loop-inspector\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path:
npm ERR!    '/usr/lib/node_modules/pm2/node_modules/event-loop-inspector' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/centos/.npm/_logs/2018-08-28T10_08_35_286Z-debug.log
[PM2][Module][ERROR] event-loop-inspector installation has FAILED (checkout previous logs)g installable status
[PM2] App [pm2-server-monit] launched (1 instances)
== pm2-server-monit ==
┌────────────────┬───────┐
│ key            │ value │
├────────────────┼───────┤
│ drive          │ /     │
│ small_interval │ 1     │
└────────────────┴───────┘
[PM2][Module] Module successfully installed and launched
[PM2][Module] Edit configuration via: `pm2 conf`
npm ERR! code E503
npm ERR! 503 No backends available: @pm2/io@~2.1.0

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/centos/.npm/_logs/2018-08-28T10_12_19_542Z-debug.log
Use --update-env to update environment variables
[PM2] Applying action reloadProcessId on app [all](ids: 0,1)
[PM2] [graph-server](1) ✓
[PM2] [gtin-api](0) ✓
[PM2 I/O] Remote dashboard: https://app.pm2.io/#/r/key
┌──────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬────────┬──────────┐
│ App name     │ id │ mode │ pid   │ status │ restart │ uptime │ cpu │ mem       │ user   │ watching │
├──────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼────────┼──────────┤
│ graph-server │ 1  │ fork │ 31838 │ online │ 4       │ 0s     │ 0%  │ 13.1 MB   │ centos │ disabled │
│ gtin-api     │ 0  │ fork │ 31844 │ online │ 1       │ 0s     │ 0%  │ 11.3 MB   │ centos │ enabled  │
└──────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴────────┴──────────┘
 Module activated
┌──────────────────┬─────────┬────────────┬────────┬─────────┬──────┬─────────────┬────────┐
│ Module           │ version │ target PID │ status │ restart │ cpu  │ memory      │ user   │
├──────────────────┼─────────┼────────────┼────────┼─────────┼──────┼─────────────┼────────┤
│ pm2-server-monit │ 2.6.2   │ N/A        │ online │ 0       │ 4.5% │ 31.660 MB   │ centos │
└──────────────────┴─────────┴────────────┴────────┴─────────┴──────┴─────────────┴────────┘
 Use `pm2 show <id|name>` to get more details about an app

Deprecation warning in node 12.2.0

[DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
warn DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
    at Object.extractSocket (/usr/local/lib/node_modules/pm2/node_modules/event-loop-inspector/utils.js:33:44)
    at /usr/local/lib/node_modules/pm2/node_modules/event-loop-inspector/index.js:39:17
    at Array.forEach (<anonymous>)
    at Object.dump (/usr/local/lib/node_modules/pm2/node_modules/event-loop-inspector/index.js:22:42)
    at Timeout._onTimeout (/usr/local/lib/node_modules/pm2/node_modules/@pm2/io/build/main/src/features/actions.js:18:96)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

PM2 depends on your module, so please fix it to support Node 12.x without deprecation warnings.

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.