prometheus-plugin-gc-stats
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

prometheus-plugin-gc-stats

Node.js prometheus client plugin for exporting v8 garbadge collection statistics.

build status coverage report

Installation

npm i -S prometheus-plugin-gc-stats

Requirements

  • >=prom-client-4.0.0 npm module (installed as peer dependency). If your project depends on previous version of client this plugin might not work.
  • >=node-4.0.0 because this module uses ES6 syntax

Metric list

  • GC duration

    • type: 'Histogram'
    • name: 'nodejs_gc_duration_ms'
    • labels: ['type']
  • GC reclaimed bytes from used heap

    • type: 'Counter'
    • name: 'nodejs_gc_used_heap_reclaimed_bytes'
    • labels: ['type']

Usage

Simple

const client = require('prom-client');
const gcStatsPlugin = require('prometheus-plugin-gc-stats');
 
// start metrics collection
gcStatsPlugin.start();
 
// log metrics to console
console.log(client.register.metrics());
 
// stop metrics collection
gcStatsPlugin.stop();
 
// stop and clear metrics register
gcStatsPlugin.clear();

Override metric defaults

const client = require('prom-client');
const gcStatsPlugin = require('prometheus-plugin-gc-stats');
const override = {
  'nodejs_gc_used_heap_reclaimed_bytes': { // provide default metric name to override it's params
    type: 'Counter', // could be changed to Gaguge, but it's not recommended
    name: 'my_reclaimed_bytes', // name could be changed
    description: 'My custom description', // description could be changed
    labelValues: { // additional labels
      customLabel: 'hello', // custom labels could be added
      customFnLabel: () => { return new Date() } // if it's a function, it will be called to get label value in runtime
    }
  }
};
// start metrics collection
gcStatsPlugin.init(override).start(); // pass override object to init function
 
// log metrics to console
console.log(client.register.metrics());
 
// stop metrics collection
gcStatsPlugin.stop();
 
// stop and clear metrics register
gcStatsPlugin.reset();

Alternatives

Package Sidebar

Install

npm i prometheus-plugin-gc-stats

Weekly Downloads

8

Version

2.3.0

License

UNLICENSE

Last publish

Collaborators

  • m03geek