Collect durations through convenient start/stop methods.
Atelemetry
plugin.
Click to expand
const telemetry = require('@telemetry-js/telemetry')()
const stopwatch = require('@telemetry-js/collector-stopwatch')
const selectDuration = stopwatch('select_query.duration')
telemetry.task()
.collect(selectDuration)
.schedule(..)
// Elsewhere in your app
const stop = selectDuration.start()
// Sometime later
stop()
You can start()
multiple stopwatches (if you want them to have the same metric name) repeatedly and/or in parallel. The following example will result in two emitted metrics with the elapsed milliseconds between the start()
and stop()
calls: ~1000 and ~5000.
const stop = selectDuration.start()
const stop2 = selectDuration.start()
setTimeout(stop, 1000)
setTimeout(stop2, 5000)
If you need multiple distinct metric names, create multiple plugins:
const selectDuration = stopwatch('select_query.duration')
const insertDuration = stopwatch('insert_query.duration')
telemetry.task()
.collect(selectDuration)
.collect(insertDuration)
Yet to document.
With npm do:
npm install @telemetry-js/collector-stopwatch
This project is kindly sponsored by Reason Cybersecurity Ltd.
MIT © Vincent Weevers