项目作者: telemetry-js

项目描述 :
Collect durations through convenient start/stop methods.
高级语言: JavaScript
项目地址: git://github.com/telemetry-js/collector-stopwatch.git
创建时间: 2020-12-08T14:01:10Z
项目社区:https://github.com/telemetry-js/collector-stopwatch

开源协议:MIT License

下载


collector-stopwatch

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

@telemetry-js/collector-stopwatch"">npm status
@telemetry-js/collector-stopwatch"">node
Test
JavaScript Style Guide

Table of Contents

Click to expand

- Usage
- Options
- Install
- Acknowledgements
- License

Usage

  1. const telemetry = require('@telemetry-js/telemetry')()
  2. const stopwatch = require('@telemetry-js/collector-stopwatch')
  3. const selectDuration = stopwatch('select_query.duration')
  4. telemetry.task()
  5. .collect(selectDuration)
  6. .schedule(..)
  7. // Elsewhere in your app
  8. const stop = selectDuration.start()
  9. // Sometime later
  10. 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.

  1. const stop = selectDuration.start()
  2. const stop2 = selectDuration.start()
  3. setTimeout(stop, 1000)
  4. setTimeout(stop2, 5000)

If you need multiple distinct metric names, create multiple plugins:

  1. const selectDuration = stopwatch('select_query.duration')
  2. const insertDuration = stopwatch('insert_query.duration')
  3. telemetry.task()
  4. .collect(selectDuration)
  5. .collect(insertDuration)

Options

Yet to document.

Install

With npm do:

  1. npm install @telemetry-js/collector-stopwatch

Acknowledgements

This project is kindly sponsored by Reason Cybersecurity Ltd.

reason logo

License

MIT © Vincent Weevers