Socket
Book a DemoInstallSign in
Socket

exframe-metrics

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exframe-metrics

Utility functions for instrumenting metrics.

1.5.0
latest
Source
npmnpm
Version published
Weekly downloads
1.6K
18.48%
Maintainers
1
Weekly downloads
 
Created
Source

exframe-metrics

Utility functions for instrumenting metrics.

Install

npm install exframe-metrics

Usage

instrument

instrument function takes a function as input, adds duration histogram and count metrics to it, executes it, and returns a Promise that is fulfilled with result of the function.

const myFunction = () => 'banana';

const result = await instrument(myFunction);

console.log(result);
// > banana

console.log(await prometheusClient.register.metrics());
// # HELP function_myFunction_duration_seconds Length of time, in seconds, the function took to complete
// # TYPE function_myFunction_duration_seconds histogram
// function_myFunction_duration_seconds_bucket{le="0.005"} 1
// function_myFunction_duration_seconds_bucket{le="0.01"} 1
// function_myFunction_duration_seconds_bucket{le="0.025"} 1
// function_myFunction_duration_seconds_bucket{le="0.05"} 1
// function_myFunction_duration_seconds_bucket{le="0.1"} 1
// function_myFunction_duration_seconds_bucket{le="0.25"} 1
// function_myFunction_duration_seconds_bucket{le="0.5"} 1
// function_myFunction_duration_seconds_bucket{le="1"} 1
// function_myFunction_duration_seconds_bucket{le="2.5"} 1
// function_myFunction_duration_seconds_bucket{le="5"} 1
// function_myFunction_duration_seconds_bucket{le="10"} 1
// function_myFunction_duration_seconds_bucket{le="+Inf"} 1
// function_myFunction_duration_seconds_sum 0.000182651
// function_myFunction_duration_seconds_count 1

// # HELP function_myFunction_calls_total Total number of times the function was called
// # TYPE function_myFunction_calls_total counter
// function_myFunction_calls_total 1

lazyInstrument

lazyInstrument function has a similar outcome as instrument except that it does not execute the input function directly and instead returns a different async function, instrumented with metrics, that can be called later. Useful for generating middleware functions.

const myFunction = () => 'banana';

const myDeferredFunction = await lazyInstrument(myFunction);

const result = await myDeferredFunction();

console.log(result);
// > banana

API

instrument(fn, options?)

Returns a Promise that is either fulfilled with the input function's result, or rejected with an error if the function throws.

fn

Type: function

Function to be instrumented. Default metrics added are:

  • duration: Histogram metric that measures the total time the function took to execute. The default name of this metric is "function_<function_name>_duration_seconds"
  • count: Counter metric that measures the total number of calls to the function with the same name (or metricName if provided). The default name of this metrics is: "function_<function_name>_calls_total"

options

Type: object

metricName

Type: String

Overrides the fn name to use for the base part of the metric names. Note: This property is required if an anonymous function is provided

metricPrefix

Type: String

String to prepend to an auto-generated metric name. Ignored if metricName is provided

FAQs

Package last updated on 05 Mar 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.