Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Latest commit

 

History

History
168 lines (120 loc) · 4.65 KB

File metadata and controls

168 lines (120 loc) · 4.65 KB

node-performance-emitter

Build status

A tool for collecting, aggregating, and emitting Node.js performance stats.

Collects stats on the event loop lag, garbage collection events, and memory statistics.


Table of contents


Installation

yarn add fusion-plugin-node-performance-emitter

Usage

// src/performance-logging.js
import {createPlugin} from 'fusion-core';
import {UniversalEventsToken} from 'fusion-plugin-universal-events';

export default createPlugin({
  deps: { emitter: UniversalEventsToken },
  provides: deps => {
    const emitter = deps.emitter;
    emitter.on('node-performance-emitter:{action}', e => {
      console.log(e); // log events to console
    });
  }
});

Setup

// src/main.js
import App from 'fusion-core';
import NodePerformanceEmitter, {
  NodePerformanceEmitterToken,
  TimersToken,
  EventLoopLagIntervalToken,
  MemoryIntervalToken,
  SocketIntervalToken
} from 'fusion-plugin-node-performance-emitter';
import UniversalEvents, {UniversalEventsToken} from 'fusion-plugin-universal-events';

export default function() {
  const app = new App(...);

  app.register(UniversalEventsToken, UniversalEvents);
  if (__NODE__) {
    app.register(TimersToken, {setInterval, clearInterval}); // optional
    app.register(EventLoopLagIntervalToken, 10000); // optional
    app.register(MemoryIntervalToken, 10000); // optional
    app.register(SocketIntervalToken, 10000); // optional
    app.register(NodePerformanceEmitterToken, NodePerformanceEmitter);
  }

return app;
}

API

Registration API

NodePerformanceEmitter
import NodePerformanceEmitter from 'fusion-plugin-node-performance-emitter';

The plugin. Should typically be registered to NodePerformanceEmitterToken.

NodePerformanceEmitterToken
import {NodePerformanceEmitterToken} from 'fusion-plugin-node-performance-emitter';

Typically should be registered with NodePerformanceEmitter

Dependencies

UniversalEventsToken

Required. See https://github.com/fusionjs/fusion-plugin-universal-events

TimersToken
import {TimersToken} from 'fusion-plugin-node-performance-emitter';

Optional. Server-only. Register a setInterval/clearInterval implementation. Defaults to the global timer functions. Useful for testing.

Types
type Timers = {
  setInterval: (Function, number) => number,
  clearInterval: (number) => void,
}
EventLoopLagIntervalToken
import {EventLoopLagIntervalToken} from 'fusion-plugin-node-performance-emitter';

Optional. Server-only. The interval between event loop lag measurements. Defaults to 10000.

MemoryIntervalToken
import {MemoryIntervalToken} from 'fusion-plugin-node-performance-emitter';

Optional. Server-only. The interval between memory measurements. Defaults to 10000.

SocketIntervalToken
import {SocketIntervalToken} from 'fusion-plugin-node-performance-emitter';

Optional. Server-only. The interval between event socket usage measurements. Defaults to 10000.

Events

This package has no public API methods. To consume performance events, add an event listener for one of the following events:

  • node-performance-emitter:gauge:event_loop_lag
  • node-performance-emitter:gauge:rss- process.memoryUsage().rss
  • node-performance-emitter:gauge:externalMemory - process.memoryUsage().external
  • node-performance-emitter:gauge:heapTotal - process.memoryUsage().heapTotal
  • node-performance-emitter:gauge:heapUsed - process.memoryUsage().heapUsed
  • node-performance-emitter:timing:gc - time spent doing garbage collection
  • node-performance-emitter:gauge:globalAgentSockets - http.globalAgent.sockets
  • node-performance-emitter:gauge:globalAgentRequests- http.globalAgent.requests
  • node-performance-emitter:gauge:globalAgentFreeSockets- http.globalAgent.freeSockets