Report Nodejs Garbage Collection stats using Prometheus
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()
The module doing the GC stats collecting is node:v8
. This module uses features that require Nodejs v18+.
This module exposes 3 metrics:
nodejs_gc_runs_total
: Counts the number of time GC is invokednodejs_gc_pause_seconds_total
: Time spent in GC in secondsnodejs_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_',
});
Thanks to @tcolgate and @SimenB for the original implementation.