Skip to content

ChainSafe/node-prometheus-gc-stats

 
 

Repository files navigation

@chainsafe/prometheus-gc-stats

Report Nodejs Garbage Collection stats using Prometheus

NPM Version

Usage

This module has a peer dependency on prom-client. Currently, 10 is supported.

Collection of GC stats is automatically started when calling gcStats and is stopped when calling the returned function.

Example:

import prometheus from 'prom-client';
import { gcStats } from '@chainsafe/prometheus-gc-stats';

prometheus.collectDefaultMetrics();
const stopGcStats = gcStats(prometheus.register);

// eventually
stopGcStats()

node:v8

The module doing the GC stats collecting is node:v8. This module uses features that require Nodejs v18+.

Metrics exposed

This module exposes 3 metrics:

  1. nodejs_gc_runs_total: Counts the number of time GC is invoked
  2. nodejs_gc_pause_seconds_total: Time spent in GC in seconds
  3. nodejs_gc_reclaimed_bytes_total: The number of bytes GC has freed

You can add a prefix to metric names using options:

const stopGcStats = gcStats(prometheus.register, {
  prefix: 'my_application_',
});

Credits

Thanks to @tcolgate and @SimenB for the original implementation.

About

Report Garbage Collection stats using Prometheus

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%