to watch, observe, or check closely
or continuously.
Source: Merriam-Webster
to give a brief description that provides
information about [something].
Source: Merriam-Webster
a mark left by something that has passed or is past.
to follow the footprints of, track, or trail of.
Source: Merriam-Webster
Monitoring Node.js applications is
a production concern...
There are new Node.js core modules
intended to help make monitoring
easier in the future.
Tracking asynchronous context...
const { createHook } = require('async_hooks')
const asyncHook = createHook({
init(id, type, triggerAsyncId, resource) { },
before(id) { },
after(id) { },
destroy(id) { },
promiseResolve(id) { }
})
asyncHook.enable()
Provides an AsyncResource
class.
There are two kinds of resources:
Demo!
Ad hoc timing metrics
const { PerformanceObserver, performance } = require('perf_hooks')
const obs = new PerformanceObserver((items) => {
console.log(items.getEntries()[0].duration)
})
obs.observe({ entryTypes: ['measure'] })
performance.mark('A')
doSomeLongRunningProcess(() => {
performance.mark('B')
performance.measure('A to B', 'A', 'B')
})
Demo!
This is the same Performance API
implemented by browsers, with a few
Node.js specific additions.
const { createTracing } = require('trace_events')
const categories = [ 'node.perf', 'node.async_hooks' ]
const tracing = createTracing({ categories })
tracing.enable()
// do stuff
tracing.disable()
const CDP = require('chrome-remote-interface')
const client = await CDP({port: args.port})
client.NodeTracing.tracingComplete(() => client.close())
client.on('event', (message) => { })
await client.NodeTracing.start({
traceConfig: {
recordMode: 'recordContinuously',
includedCategories: ['node'],
}
})
setTimeout(() => client.NodeTracing.stop(), 10000).unref()
Profiling involves collecting
and analyzing performance and
operation metrics for discreet
parts of a Node.js app within
a fixed period of time.
$ npm i -g clinic
$ clinic flame -- node some.application.js
$ npm i -g clinic
$ clinic doctor -- node some.application.js
$ npm i -g clinic
$ clinic bubbleprof -- node some.application.js
Profiling tools build on primitives
like async_hooks, trace events,
and --prof to build a snapshot of
what your application is doing
at a given point in time.
Tracing is a record of what is happening
within the process.
Current efforts with Node.js are focusing
on the platform independent
V8 Trace Events Format.
{ traceEvents: [{
pid: 22893,
tid: 22893,
ts: 110377229940,
tts: 164935,
ph: 'b',
cat: 'node,node.async_hooks',
name: 'TickObject_CALLBACK',
dur: 0,
tdur: 0,
id: '0x25',
args: {}
]
},
We are actively expanding the
information emitted as trace events.
Demo!
Node.js Diagnostics Working Group
http://github.com/nodejs/diagnostics
Come talk to us if you need help with your Node.js
- Twitter: [@jasnell](https://twitter.com/jasnell) - GitHub: [@jasnell](https://github.com/jasnell)