Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fresh8/prom-client-timer-unit

Package Overview
Dependencies
Maintainers
6
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fresh8/prom-client-timer-unit

A helper function to help record time in other units than seconds.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
6
Weekly downloads
 
Created
Source

prom-client-timer-unit

CircleCI Coverage Status styled with prettier

A helper function to help record time in other units than seconds. It really just divides the time measurment (in seconds) by whatever number you give it.

Usage

At a glance

Javascript
const myMetric = require('prom-client').Histogram()
const startTimer = require('@fresh8/prom-client-timer-unit')

const stopTimer = startTimer(myMetric, 1e-3)
// [...] your code doing things
stopTimer() // will calculate the time elapsed and register it in `myMetric`
Typescript
import * as promClient from 'prom-client'
import * as startTimer from '@fresh8/prom-client-timer-unit'

const myMetric = promClient.Histogram()
const stopTimer = startTimer(myMetric, 1e-3)
// [...] your code doing things
stopTimer() // will calculate the time elapsed and register it in `myMetric`

API

startTimer(metric, factor, labels)
  • metric : The prom-client metric, e.g: new promClient.Histogram(opts)
  • factor (optional): The factor to be applied to the observed number of seconds. Examples: 1e-3 for milliseconds, 60 for minutes. Defaults to 1
  • labels (optional): Labels to apply to the observation. This is to follow the same signature as the original startTimer function in prom-client. Defaults to {}
  • returns: stopTimer

Starts counting time using process.hrtime.

stopTimer(labels)
  • labels : Labels to apply to the observation. They will be merged with the labels given to startTimer (if any). Defaults to {}
  • returns: { labels, elapsed }. This is in case you want to re-use those values in something else than prometheus itself. ** labels: the result of combining labels given to startTimer and stopTimer ** elapsed: the time measured by the timer, in the correct unit.

Stops the timer and record the elapsed time in seconds divided by factor.

Credits

Implementation very heavily inspired from the original in prom-client

FAQs

Package last updated on 06 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc