Skip to content

telemetry-js/collector-stopwatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Collect durations through convenient start/stop methods.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published