A tool for collecting, aggregating, and emitting Node.js performance stats.
Collects stats on the event loop lag, garbage collection events, and memory statistics.
yarn add fusion-plugin-node-performance-emitter
// 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
});
}
});
// 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;
}
import NodePerformanceEmitter from 'fusion-plugin-node-performance-emitter';
The plugin. Should typically be registered to NodePerformanceEmitterToken
.
import {NodePerformanceEmitterToken} from 'fusion-plugin-node-performance-emitter';
Typically should be registered with NodePerformanceEmitter
Required. See https://github.com/fusionjs/fusion-plugin-universal-events
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.
type Timers = {
setInterval: (Function, number) => number,
clearInterval: (number) => void,
}
import {EventLoopLagIntervalToken} from 'fusion-plugin-node-performance-emitter';
Optional. Server-only. The interval between event loop lag measurements. Defaults to 10000
.
import {MemoryIntervalToken} from 'fusion-plugin-node-performance-emitter';
Optional. Server-only. The interval between memory measurements. Defaults to 10000
.
import {SocketIntervalToken} from 'fusion-plugin-node-performance-emitter';
Optional. Server-only. The interval between event socket usage measurements. Defaults to 10000
.
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().rssnode-performance-emitter:gauge:externalMemory
- process.memoryUsage().externalnode-performance-emitter:gauge:heapTotal
- process.memoryUsage().heapTotalnode-performance-emitter:gauge:heapUsed
- process.memoryUsage().heapUsednode-performance-emitter:timing:gc
- time spent doing garbage collectionnode-performance-emitter:gauge:globalAgentSockets
- http.globalAgent.socketsnode-performance-emitter:gauge:globalAgentRequests
- http.globalAgent.requestsnode-performance-emitter:gauge:globalAgentFreeSockets
- http.globalAgent.freeSockets