@telemetry-js/collector-stopwatch

0.0.3 • Public • Published

collector-stopwatch

Collect durations through convenient start/stop methods.
A telemetry plugin.

npm status node Test JavaScript Style Guide

Table of Contents

Click to expand

Usage

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)

Options

Yet to document.

Install

With npm do:

npm install @telemetry-js/collector-stopwatch

Acknowledgements

This project is kindly sponsored by Reason Cybersecurity Ltd.

reason logo

License

MIT © Vincent Weevers

Package Sidebar

Install

npm i @telemetry-js/collector-stopwatch

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

6 kB

Total Files

4

Last publish

Collaborators

  • vweevers