Package detail

prom-client

siimon12.2mApache-2.015.1.3

Client for prometheus

Prometheus, Metrics, Client

readme

Prometheus client for node.js Actions Status

A prometheus client for Node.js that supports histogram, summaries, gauges and counters.

Usage

See example folder for a sample usage. The library does not bundle any web framework. To expose the metrics, respond to Prometheus's scrape requests with the result of await registry.metrics().

Usage with Node.js's cluster module

Node.js's cluster module spawns multiple processes and hands off socket connections to those workers. Returning metrics from a worker's local registry will only reveal that individual worker's metrics, which is generally undesirable. To solve this, you can aggregate all of the workers' metrics in the master process. See example/cluster.js for an example.

Default metrics use sensible aggregation methods. (Note, however, that the event loop lag mean and percentiles are averaged, which is not perfectly accurate.) Custom metrics are summed across workers by default. To use a different aggregation method, set the aggregator property in the metric config to one of 'sum', 'first', 'min', 'max', 'average' or 'omit'. (See lib/metrics/version.js for an example.)

If you need to expose metrics about an individual worker, you can include a value that is unique to the worker (such as the worker ID or process ID) in a label. (See example/server.js for an example using worker_${cluster.worker.id} as a label value.)

Metrics are aggregated from the global registry by default. To use a different registry, call client.AggregatorRegistry.setRegistries(registryOrArrayOfRegistries) from the worker processes.

API

Default metrics

There are some default metrics recommended by Prometheus itself. To collect these, call collectDefaultMetrics. In addition, some Node.js-specific metrics are included, such as event loop lag, active handles, GC and Node.js version. See lib/metrics for a list of all metrics.

NOTE: Some of the metrics, concerning File Descriptors and Memory, are only available on Linux.

collectDefaultMetrics optionally accepts a config object with following entries:

  • prefix an optional prefix for metric names. Default: no prefix.
  • register to which registry the metrics should be registered. Default: the global default registry.
  • gcDurationBuckets with custom buckets for GC duration histogram. Default buckets of GC duration histogram are [0.001, 0.01, 0.1, 1, 2, 5] (in seconds).
  • eventLoopMonitoringPrecision with sampling rate in milliseconds. Must be greater than zero. Default: 10.

To register metrics to another registry, pass it in as register:

const client = require('prom-client');
const collectDefaultMetrics = client.collectDefaultMetrics;
const Registry = client.Registry;
const register = new Registry();
collectDefaultMetrics({ register });

To use custom buckets for GC duration histogram, pass it in as gcDurationBuckets:

const client = require('prom-client');
const collectDefaultMetrics = client.collectDefaultMetrics;
collectDefaultMetrics({ gcDurationBuckets: [0.1, 0.2, 0.3] });

To prefix metric names with your own arbitrary string, pass in a prefix:

const client = require('prom-client');
const collectDefaultMetrics = client.collectDefaultMetrics;
const prefix = 'my_application_';
collectDefaultMetrics({ prefix });

To apply generic labels to all default metrics, pass an object to the labels property (useful if you're working in a clustered environment):

const client = require('prom-client');
const collectDefaultMetrics = client.collectDefaultMetrics;
collectDefaultMetrics({
  labels: { NODE_APP_INSTANCE: process.env.NODE_APP_INSTANCE },
});

You can get the full list of metrics by inspecting client.collectDefaultMetrics.metricsList.

Default metrics are collected on scrape of metrics endpoint, not on an interval.

const client = require('prom-client');

const collectDefaultMetrics = client.collectDefaultMetrics;

collectDefaultMetrics();

Custom Metrics

All metric types have two mandatory parameters: name and help. Refer to https://prometheus.io/docs/practices/naming/ for guidance on naming metrics.

For metrics based on point-in-time observations (e.g. current memory usage, as opposed to HTTP request durations observed continuously in a histogram), you should provide a collect() function, which will be invoked when Prometheus scrapes your metrics endpoint. collect() can either be synchronous or return a promise. See Gauge below for an example. (Note that you should not update metric values in a setInterval callback; do so in this collect function instead.)

See Labels for information on how to configure labels for all metric types.

Counter

Counters go up, and reset when the process restarts.

const client = require('prom-client');
const counter = new client.Counter({
  name: 'metric_name',
  help: 'metric_help',
});
counter.inc(); // Increment by 1
counter.inc(10); // Increment by 10

Gauge

Gauges are similar to Counters but a Gauge's value can be decreased.

const client = require('prom-client');
const gauge = new client.Gauge({ name: 'metric_name', help: 'metric_help' });
gauge.set(10); // Set to 10
gauge.inc(); // Increment 1
gauge.inc(10); // Increment 10
gauge.dec(); // Decrement by 1
gauge.dec(10); // Decrement by 10
Configuration

If the gauge is used for a point-in-time observation, you should provide a collect function:

const client = require('prom-client');
new client.Gauge({
  name: 'metric_name',
  help: 'metric_help',
  collect() {
    // Invoked when the registry collects its metrics' values.
    // This can be synchronous or it can return a promise/be an async function.
    this.set(/* the current value */);
  },
});
// Async version:
const client = require('prom-client');
new client.Gauge({
  name: 'metric_name',
  help: 'metric_help',
  async collect() {
    // Invoked when the registry collects its metrics' values.
    const currentValue = await somethingAsync();
    this.set(currentValue);
  },
});

Note that you should not use arrow functions for collect because arrow functions will not have the correct value for this.

Utility Functions
// Set value to current time in seconds:
gauge.setToCurrentTime();

// Record durations:
const end = gauge.startTimer();
http.get('url', res => {
  end();
});

Histogram

Histograms track sizes and frequency of events.

Configuration

The defaults buckets are intended to cover usual web/RPC requests, but they can be overridden. (See also Bucket Generators.)

const client = require('prom-client');
new client.Histogram({
  name: 'metric_name',
  help: 'metric_help',
  buckets: [0.1, 5, 15, 50, 100, 500],
});
Examples
const client = require('prom-client');
const histogram = new client.Histogram({
  name: 'metric_name',
  help: 'metric_help',
});
histogram.observe(10); // Observe value in histogram
Utility Methods
const end = histogram.startTimer();
xhrRequest(function (err, res) {
  const seconds = end(); // Observes and returns the value to xhrRequests duration in seconds
});

Summary

Summaries calculate percentiles of observed values.

Configuration

The default percentiles are: 0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999. But they can be overridden by specifying a percentiles array. (See also Bucket Generators.)

const client = require('prom-client');
new client.Summary({
  name: 'metric_name',
  help: 'metric_help',
  percentiles: [0.01, 0.1, 0.9, 0.99],
});

To enable the sliding window functionality for summaries you need to add maxAgeSeconds and ageBuckets to the config like this:

const client = require('prom-client');
new client.Summary({
  name: 'metric_name',
  help: 'metric_help',
  maxAgeSeconds: 600,
  ageBuckets: 5,
  pruneAgedBuckets: false,
});

The maxAgeSeconds will tell how old a bucket can be before it is reset and ageBuckets configures how many buckets we will have in our sliding window for the summary. If pruneAgedBuckets is false (default), the metric value will always be present, even when empty (its percentile values will be 0). Set pruneAgedBuckets to true if you don't want to export it when it is empty.

Examples
const client = require('prom-client');
const summary = new client.Summary({
  name: 'metric_name',
  help: 'metric_help',
});
summary.observe(10);
Utility Methods
const end = summary.startTimer();
xhrRequest(function (err, res) {
  end(); // Observes the value to xhrRequests duration in seconds
});

Labels

All metrics can take a labelNames property in the configuration object. All label names that the metric support needs to be declared here. There are two ways to add values to the labels:

const client = require('prom-client');
const gauge = new client.Gauge({
  name: 'metric_name',
  help: 'metric_help',
  labelNames: ['method', 'statusCode'],
});

// 1st version: Set value to 100 with "method" set to "GET" and "statusCode" to "200"
gauge.set({ method: 'GET', statusCode: '200' }, 100);
// 2nd version: Same effect as above
gauge.labels({ method: 'GET', statusCode: '200' }).set(100);
// 3rd version: And again the same effect as above
gauge.labels('GET', '200').set(100);

It is also possible to use timers with labels, both before and after the timer is created:

const end = startTimer({ method: 'GET' }); // Set method to GET, we don't know statusCode yet
xhrRequest(function (err, res) {
  if (err) {
    end({ statusCode: '500' }); // Sets value to xhrRequest duration in seconds with statusCode 500
  } else {
    end({ statusCode: '200' }); // Sets value to xhrRequest duration in seconds with statusCode 200
  }
});

Zeroing metrics with Labels

Metrics with labels can not be exported before they have been observed at least once since the possible label values are not known before they're observed.

For histograms, this can be solved by explicitly zeroing all expected label values:

const histogram = new client.Histogram({
  name: 'metric_name',
  help: 'metric_help',
  buckets: [0.1, 5, 15, 50, 100, 500],
  labels: ['method'],
});
histogram.zero({ method: 'GET' });
histogram.zero({ method: 'POST' });

Strongly typed Labels

Typescript can also enforce label names using as const

import * as client from 'prom-client';

const counter = new client.Counter({
  name: 'metric_name',
  help: 'metric_help',
  // add `as const` here to enforce label names
  labelNames: ['method'] as const,
});

// Ok
counter.inc({ method: 1 });

// this is an error since `'methods'` is not a valid `labelName`
// @ts-expect-error
counter.inc({ methods: 1 });

Default Labels (segmented by registry)

Static labels may be applied to every metric emitted by a registry:

const client = require('prom-client');
const defaultLabels = { serviceName: 'api-v1' };
client.register.setDefaultLabels(defaultLabels);

This will output metrics in the following way:

# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes{serviceName="api-v1"} 33853440 1498510040309

Default labels will be overridden if there is a name conflict.

register.clear() will clear default labels.

Exemplars

The exemplars defined in the OpenMetrics specification can be enabled on Counter and Histogram metric types. The default metrics have support for OpenTelemetry, they will populate the exemplars with the labels {traceId, spanId} and their corresponding values.

The format for inc() and observe() calls are different if exemplars are enabled. They get a single object with the format {labels, value, exemplarLabels}.

When using exemplars, the registry used for metrics should be set to OpenMetrics type (including the global or default registry if no registries are specified).

Registry type

The library supports both the old Prometheus format and the OpenMetrics format. The format can be set per registry. For default metrics:

const Prometheus = require('prom-client');
Prometheus.register.setContentType(
  Prometheus.Registry.OPENMETRICS_CONTENT_TYPE,
);

Currently available registry types are defined by the content types:

PROMETHEUS_CONTENT_TYPE - version 0.0.4 of the original Prometheus metrics, this is currently the default registry type.

OPENMETRICS_CONTENT_TYPE - defaults to version 1.0.0 of the OpenMetrics standard.

The HTTP Content-Type string for each registry type is exposed both at module level (prometheusContentType and openMetricsContentType) and as static properties on the Registry object.

The contentType constant exposed by the module returns the default content type when creating a new registry, currently defaults to Prometheus type.

Multiple registries

By default, metrics are automatically registered to the global registry (located at require('prom-client').register). You can prevent this by specifying registers: [] in the metric constructor configuration.

Using non-global registries requires creating a Registry instance and passing it inside registers in the metric configuration object. Alternatively you can pass an empty registers array and register it manually.

Registry has a merge function that enables you to expose multiple registries on the same endpoint. If the same metric name exists in both registries, an error will be thrown.

Merging registries of different types is undefined. The user needs to make sure all used registries have the same type (Prometheus or OpenMetrics versions).

const client = require('prom-client');
const registry = new client.Registry();
const counter = new client.Counter({
  name: 'metric_name',
  help: 'metric_help',
  registers: [registry], // specify a non-default registry
});
const histogram = new client.Histogram({
  name: 'metric_name',
  help: 'metric_help',
  registers: [], // don't automatically register this metric
});
registry.registerMetric(histogram); // register metric manually
counter.inc();

const mergedRegistries = client.Registry.merge([registry, client.register]);

If you want to use multiple or non-default registries with the Node.js cluster module, you will need to set the registry/registries to aggregate from:

const AggregatorRegistry = client.AggregatorRegistry;
AggregatorRegistry.setRegistries(registry);
// or for multiple registries:
AggregatorRegistry.setRegistries([registry1, registry2]);

Register

You can get all metrics by running await register.metrics(), which will return a string in the Prometheus exposition format.

Getting a single metric value in Prometheus exposition format

If you need to output a single metric in the Prometheus exposition format, you can use await register.getSingleMetricAsString(*name of metric*), which will return a string for Prometheus to consume.

Getting a single metric

If you need to get a reference to a previously registered metric, you can use register.getSingleMetric(*name of metric*).

Removing metrics

You can remove all metrics by calling register.clear(). You can also remove a single metric by calling register.removeSingleMetric(*name of metric*).

Resetting metrics

If you need to reset all metrics, you can use register.resetMetrics(). The metrics will remain present in the register and can be used without the need to instantiate them again, like you would need to do after register.clear().

Cluster metrics

You can get aggregated metrics for all workers in a Node.js cluster with await register.clusterMetrics(). This method returns a promise that resolves with a metrics string suitable for Prometheus to consume.

const metrics = await register.clusterMetrics();

// - or -

register
  .clusterMetrics()
  .then(metrics => {
    /* ... */
  })
  .catch(err => {
    /* ... */
  });

Pushgateway

It is possible to push metrics via a Pushgateway.

const client = require('prom-client');
let gateway = new client.Pushgateway('http://127.0.0.1:9091');

gateway.pushAdd({ jobName: 'test' })
    .then(({resp, body}) => {
        /* ... */
    })
    .catch(err => {
        /* ... */
    })); //Add metric and overwrite old ones
gateway.push({ jobName: 'test' })
    .then(({resp, body}) => {
        /* ... */
    })
    .catch(err => {
        /* ... */
    })); //Overwrite all metrics (use PUT)
gateway.delete({ jobName: 'test' })
    .then(({resp, body}) => {
        /* ... */
    })
    .catch(err => {
        /* ... */
    })); //Delete all metrics for jobName

//All gateway requests can have groupings on it
gateway.pushAdd({ jobName: 'test', groupings: { key: 'value' } })
    .then(({resp, body}) => {
        /* ... */
    })
    .catch(err => {
        /* ... */
    }));

// It's possible to extend the Pushgateway with request options from nodes core
// http/https library. In particular, you might want to provide an agent so that
// TCP connections are reused.
gateway = new client.Pushgateway('http://127.0.0.1:9091', {
  timeout: 5000, //Set the request timeout to 5000ms
  agent: new http.Agent({
    keepAlive: true,
    keepAliveMsec: 10000,
    maxSockets: 5,
  }),
});

Some gateways such as Gravel Gateway do not support grouping by job name, exposing a plain /metrics endpoint instead of /metrics/job/<jobName>. It's possible to configure a gateway instance to not require a jobName in the options argument.

gravelGateway = new client.Pushgateway('http://127.0.0.1:9091', {
  timeout: 5000,
  requireJobName: false,
});
gravelGateway.pushAdd();

Bucket Generators

For convenience, there are two bucket generator functions - linear and exponential.

const client = require('prom-client');
new client.Histogram({
  name: 'metric_name',
  help: 'metric_help',
  buckets: client.linearBuckets(0, 10, 20), //Create 20 buckets, starting on 0 and a width of 10
});

new client.Histogram({
  name: 'metric_name',
  help: 'metric_help',
  buckets: client.exponentialBuckets(1, 2, 5), //Create 5 buckets, starting on 1 and with a factor of 2
});

Garbage Collection Metrics

To avoid native dependencies in this module, GC statistics for bytes reclaimed in each GC sweep are kept in a separate module: https://github.com/SimenB/node-prometheus-gc-stats. (Note that that metric may no longer be accurate now that v8 uses parallel garbage collection.)

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

Breaking

Changed

Added

[15.1.3] - 2024-06-27

Changed

  • Improve error message when number of registered labels mismatch with the number of labels provided

[15.1.2] - 2024-04-16

Changed

  • Add Registry.PROMETHEUS_CONTENT_TYPE and Registry.OPENMETRICS_CONTENT_TYPE constants to the TypeScript types
  • Correctly read and set contentType top level export

Added

  • Enable bun.js by catching NotImplemented error (Fixes #570)

[15.1.1] - 2024-03-26

Changed

  • Improve the memory usage of histograms when the enableExemplars option is disabled
  • fix: Avoid updating exemplar values during subsequent metric changes (Fixes #616)

15.1.0 - 2023-12-15

Changed

  • remove unnecessary loop from osMemoryHeapLinux
  • Improve performance of hashObject by using pre-sorted array of label names
  • Fix type of collectDefaultMetrics.metricsList

Added

  • Allow Pushgateway to now require job names for compatibility with Gravel Gateway.
  • Allow histogram.startTime() to be used with exemplars.

15.0.0 - 2023-10-09

Breaking

  • drop support for Node.js versions 10, 12, 14, 17 and 19

Changed

  • Refactor histogram internals and provide a fast path for rendering metrics to Prometheus strings when there are many labels shared across different values.
  • Disable custom content encoding for pushgateway delete requests in order to avoid failures from the server when using Content-Encoding: gzip header.
  • Refactor escapeString helper in lib/registry.js to improve performance and avoid an unnecessarily complex regex.
  • Cleanup code and refactor to be more efficient
  • Correct TS types for working with OpenMetrics
  • Updated Typescript and Readme docs for setToCurrentTime() to reflect units as seconds.
  • Do not ignore error if request to pushgateway fails
  • Make sure to reject the request to pushgateway if it times out

Added

  • Support for OpenMetrics and Exemplars

14.2.0 - 2023-03-06

Changed

  • Refactor getMetricAsPrometheusString method in the Registry class to use Array.prototype.join instead of loop of string concatenations.
  • Also use Array.prototype.map, and object spread instead of an explicit for loop
  • changed: updated the sample output in example/default-metrics.js
  • summary metrics now has a pruneAgedBuckets config parameter to remove entries without any new values in the last maxAgeSeconds. Default is false (old behavior)

Added

  • Add get method to type definitions of metric classes

14.1.1 - 2022-12-31

Changed

  • Increase compatibility with external build system such as rollup by making perf_hooks optional in gc.js

14.1.0 - 2022-08-23

Changed

  • types: converted all the generic Metric types to be optional

  • The done() functions returned by gauge.startTimer() and summary.startTimer() now return the timed duration. Histograms already had this behavior.

  • types: fixed type for registry.getMetricsAsArray()

  • Improve performance of gague.inc() and gauge.dec() by calling hashObject() once.

Added

  • The processResources metric was added, which keeps a track of all sorts of active resources. It consists of the following gauges:

    • nodejs_active_resources - Number of active resources that are currently keeping the event loop alive, grouped by async resource type.
    • nodejs_active_resources_total - Total number of active resources. It is supposed to provide the combined result of the processHandles and processRequests metrics along with information about any other types of async resources that these metrics do not keep a track of (like timers).
  • Support gzipped pushgateway requests

14.0.1 - 2021-11-02

Changed

  • changed: typedef for pushgateway to reflect js implementation.

14.0.0 - 2021-09-18

Breaking

  • changed: linearBuckets does not propagate rounding errors anymore.

    Fewer bucket bounds will be affected by rounding errors. Histogram bucket labels may change. 6f1f3b2

  • changed: The push gateway methods pushAdd(), push() and delete() now return Promises instead of accepting a callback:

    // Old:
    gateway.pushAdd({ jobName: 'test' }, (err, resp, body) => {});
    // New:
    gateway
      .pushAdd({ jobName: 'test' })
      .then(({ resp, body }) => {})
      .catch(err => {});
    // or
    const { resp, body } = await gateway.pushAdd({ jobName: 'test' });

    f177b1f

  • changed: The default nodejs_eventloop_lag_* metrics are now reset every time they are observed. This prevents these metrics from "stabilizing" over a long period of time and becoming insensitive to small changes. For more info, see #370. 0f444cd

Changed

  • Add missing await/thens to examples. 074f339
  • Add missing type declaration for client.contentType. 3b66641
  • Modernize some label processing code. c9bf1d8

13.2.0 - 2021-08-08

Changed

  • Don't add event listener to process if cluster module is not used.
  • fix: set labels for default memory metrics on linux.
  • fix: fix DEP0152 deprecation warning in Node.js v16+.
  • fix: Set aggregation mode for newer event loop metrics. (Fixes #418)
  • Improve performance of/reduce memory allocations in Gauge.

Added

  • feat: added zero() to Histogram for setting the metrics for a given label combination to zero
  • fix: allow Gauge.inc/dec(0) without defaulting to 1

13.1.0 - 2021-01-24

Changed

  • fix: push client attempting to write Promise (fixes #390)
  • types: improve type checking of labels
  • fix: Summary#observe should throw when adding additional labels to labelset (fixes #262)

Added

  • feat: added the ability to pass labels as an object to labels() and remove()
  • Added: More examples with commented output

13.0.0 - 2020-12-16

Breaking

  • changed: The following functions are now async (return a promise): registry.metrics() registry.getMetricsAsJSON() registry.getMetricsAsArray() registry.getSingleMetricAsString()

    If your metrics server has a line like res.send(register.metrics()), you should change it to res.send(await register.metrics()).

    Additionally, all metric types now accept an optional collect function, which is called when the metric's value should be collected and within which you should set the metric's value. You should provide a collect function for point-in-time metrics (e.g. current memory usage, as opposed to HTTP request durations that are continuously logged in a histogram).

  • changed: register.clusterMetrics() no longer accepts a callback; it only returns a promise.

  • removed: v12.0.0 added the undocumented functions registry.registerCollector and registry.collectors(). These have been removed. If you were using them, you should instead provide a collect function as described above.

Changed

  • fix: provide nodejs_version_info metric value after calling registry.resetMetrics() (#238)
  • fix: provide process_max_fds metric value after calling registry.resetMetrics()
  • fix: provide process_start_time_seconds metric value after calling registry.resetMetrics()
  • chore: improve performance of registry.getMetricAsPrometheusString
  • chore: refactor metrics to reduce code duplication
  • chore: replace utils.getPropertiesFromObj with Object.values
  • chore: remove unused catch bindings
  • chore: upgrade Prettier to 2.x
  • fix: startTimer returns number in typescript instead of void
  • fix: incorrect typings of `registry.getSingleMetric' (#388)
  • chore: stop testing node v13 on CI

Added

  • feat: exposed registry.registerCollector() and registry.collectors() methods in TypeScript declaration
  • Added: complete working example of a pushgateway push in example/pushgateway.js
  • feat: added support for adding labels to default metrics (#374)
  • Added CHANGELOG reminder

12.0.0 - 2020-02-20

Breaking

  • Dropped support for end-of-life Node.js versions 6.x and 8.x
  • Dropped the previously deprecated support for positional parameters in constructors, only the config object forms remain.
  • Default metrics are collected on scrape of metrics endpoint, not on an interval. The timeout option to collectDefaultMetrics(conf) is no longer supported or needed, and the function no longer returns a Timeout object.

Changed

  • chore: remove ignored package-lock.json
  • fix: process_max_fds is process limit, not OS (#314)
  • Changed Metric labelNames & labelValues in TypeScript declaration to a generic type T extends string, instead of string
  • Lazy-load Node.js Cluster module to fix Passenger support (#293)
  • fix: avoid mutation bug in registry.getMetricsAsJSON()
  • fix: improve performance of registry.getMetrics*
  • End function of histogram startTimer, when invoked returns the number of seconds
  • chore: reindent package.json
  • chore: correct var name in processStartTime
  • chore: add test for process_start_time_seconds
  • chore: spelling corrections in README

Added

  • feat: implement GC metrics collection without native(C++) modules.
  • feat: implement advanced event loop monitoring

11.5.3 - 2019-06-27

Changed

  • Parameter compressCount in Summaries to control compression of data in t-digest.
  • Compress t-digest in Summaries

11.5.2 - 2019-06-20

Changed

  • fix: avoid mutation bug in registry

11.5.1 - 2019-06-13

Changed

  • fix: guard against missing constructor

11.5.0 - 2019-06-04

Added

  • Added timestamps toggle to collectDefaultMetrics options
  • Export validateMetricName

11.4.0 - 2019-06-04

Added

  • nodejs_active_handles metric to the collectDefaultMetrics(). Unlike nodejs_active_handles_total it split count of active handles by type.
  • nodejs_active_requests metric to the collectDefaultMetrics(). Unlike nodejs_active_requests_total it split count of active requests by type.

11.3.0 - 2019-04-02

Changed

  • Check that cluster worker is still connected before attempting to query it for metrics. (#244)

Added

11.2.1

Breaking

Changed

Added

  • Updated types for Summary in typescript definition file

11.2.0

Changed

  • Updated child dependency merge patch version to remove vulnerability.

Added

  • Added an initial benchmark suite which can be run with npm run benchmarks.
  • Add support for sliding windows in Summaries

11.1.3 - 2018-09-22

Changed

  • Fixed performance by avoiding Object.assign on hot paths, as well as mutating objects when appropriate.

11.1.2 - 2018-09-19

Changed

  • Allow setting Gauge values to NaN, +Inf, and -Inf
  • Fixed histogram scrape performance by using acc.push instead of acc.concat. Fixes #216 with #219

11.1.1 - 2018-06-29

Changed

  • Fixed processOpenFileDescriptors metric when no custom config was set

11.1.0 - 2018-06-29

  • Added ability to set a name prefix in the default metrics

Changed

  • Fixed startTimer utility to not mutate objects passed as startLabels
  • Fixed Counter to validate labels parameter of inc() against initial labelset
  • Fixed AggregatorFactory losing the aggregator method of metrics

11.0.0 - 2018-03-10

Breaking

  • Fixed gauge.setToCurrentTime() to use seconds instead of milliseconds
  • Dropped support for node 4

10.2.3 - 2018-02-28

Breaking

Changed

  • Fixed issue that registry.getMetricsAsJSON() ignores registry default labels

Added

10.2.2 - 2017-11-02

Changed

  • Fixed invalid process_virtual_memory_bytes reported under linux

10.2.1 - 2017-10-27

Changed

  • Only resolve/reject clusterMetrics promise if no callback is provided

10.2.0 - 2017-10-16

Changed

  • Don't add event listeners if cluster module is not used.
  • Fixed issue with counters having extra records when using empty labels

Added

  • Added reset to Counter and Gauge
  • Added resetMetrics to register to calling reset of all metric instances

10.1.1 - 2017-09-26

Changed

  • Update TypeScript definitions and JSDoc comments to match JavaScript sources
  • Fix lexical scope of arguments in cluster code

10.1.0 - 2017-09-04

Added

  • Support aggregating metrics across workers in a Node.js cluster.

10.0.4 - 2017-08-22

Changed

  • Include invalid values in the error messages

10.0.3 - 2017-08-07

Added

  • Added registerMetric to definitions file

Changed

  • Fixed typing of DefaultMetricsCollectorConfiguration in definitions file
  • Don't pass timestamps through to pushgateway by default

10.0.2 - 2017-07-07

Changed

  • Don't poll default metrics every single tick

10.0.1 - 2017-07-06

Added

  • Metrics should be initialized to 0 when there are no labels

10.0.0 - 2017-07-04

Breaking

  • Print deprecation warning when metrics are constructed using non-objects
  • Print deprecation warning when collectDefaultMetrics is called with a number

Added

  • Ability to set default labels by registry
  • Allow passing in registry as second argument to collectDefaultMetrics to use that instead of the default registry

Changed

  • Convert code base to ES2015 code (node 4)
    • add engines field to package.json
    • Use object shorthand
    • Remove util-extend in favor of Object.assign
    • Arrow functions over binding or putting this in a variable
    • Use template strings
    • prototype -> class

9.1.1 - 2017-06-17

Changed

  • Don't set timestamps for metrics that are never updated

9.1.0 - 2017-06-07

Added

  • Ability to merge registries

Changed

  • Correct typedefs for object constructor of metrics

9.0.0 - 2017-05-06

Added

  • Support for multiple registers
  • Support for object literals in metric constructors
  • Timestamp support

Changed

  • Collection of default metrics is now disabled by default. Start collection by running collectDefaultMetrics().

Deprecated

  • Creating metrics with one argument per parameter - use object literals instead.