# @chainsafe/prometheus-gc-stats

> Report Nodejs Garbage Collection stats using Prometheus

Latest version **1.0.2** (published 2023-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @chainsafe/prometheus-gc-stats
pnpm add @chainsafe/prometheus-gc-stats
yarn add @chainsafe/prometheus-gc-stats
bun add @chainsafe/prometheus-gc-stats
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-06-22 |
| First published | 2023-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 32.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | dapplion, wemeetagain, mpetrunic |
| Keywords | garbage-collection, gc, metrics, prometheus, prom, statsd |

## Links

- npm: https://www.npmjs.com/package/@chainsafe/prometheus-gc-stats
- Repository: https://github.com/chainsafe/node-prometheus-gc-stats
- npm.io page: https://npm.io/package/@chainsafe/prometheus-gc-stats

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-06-22
- 1.0.0 — 2023-06-21

## README

# @chainsafe/prometheus-gc-stats

> Report Nodejs Garbage Collection stats using Prometheus

[![NPM Version][npm-image]][npm-url]

## Usage

This module has a peer dependency on [`prom-client`](https://github.com/siimon/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:

```ts
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`](https://nodejs.org/api/v8.html). 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:

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

## Credits

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

[npm-url]: https://npmjs.org/package/@chainsafe/prometheus-gc-stats
[npm-image]: https://img.shields.io/npm/v/@chainsafe/prometheus-gc-stats.svg

---
_Source: https://npm.io/package/@chainsafe/prometheus-gc-stats · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
