JSPM

@telemetry-js/collector-stopwatch

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q20467F
  • License MIT

Collect durations through convenient start/stop methods

Package Exports

  • @telemetry-js/collector-stopwatch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@telemetry-js/collector-stopwatch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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