# prometheus-gc-stats

> Report Garbage Collection stats using Prometheus

Latest version **1.1.0** (published 2023-10-09) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-10-09 |
| First published | 2016-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/prometheus-gc-stats) |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 87 |
| Author | Simen Bekkhus |
| Maintainers | simenb |
| Keywords | garbage-collection, gc, metrics, prometheus, prom, statsd |

## Links

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

## Dependencies (1)

- [optional](https://npm.io/package/optional.md) ^0.1.3

## 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.1.0 (latest) — 2023-10-09
- 1.0.0 — 2023-09-06
- 0.6.5 — 2023-09-06
- 0.6.4 — 2022-12-07
- 0.6.3 — 2020-08-26
- 0.6.2 — 2019-04-23
- 0.6.1 — 2018-11-26
- 0.6.0 — 2018-08-19
- 0.5.1 — 2018-03-11
- 0.5.0 — 2017-07-04
- 0.4.0 — 2017-06-15
- 0.3.4 — 2017-05-07
- 0.3.3 — 2017-04-05
- 0.3.2 — 2017-01-05
- 0.3.1 — 2016-10-07
- … 3 more at https://npm.io/package/prometheus-gc-stats/versions

## README

# prometheus-gc-stats

> Report Garbage Collection stats using Prometheus

[![NPM Version][npm-image]][npm-url]
[![Build Status][circle-ci-image]][circle-ci-url]

## Usage

This module has a peer dependency on [`prom-client`](https://github.com/siimon/prom-client). Currently, 10-14 is supported.

Note that version 12 and up of `prom-client` comes with GC metrics out of the box, so this module might not be needed. See [this comment](https://github.com/siimon/prom-client/pull/361#discussion_r400430717).

This module follows the same API as the core default metrics. To start collection GC stats, invoke the exported function to create the
metrics, then invoke the returned function to start the collecting.

The exported function takes a single parameter, which is a registry. If provided, and the version of prom-client you use support it, that is
the registry which the metrics will register to. If no registry is provided it will use the default one provided by `prom-client`.

Example:

```js
const prometheus = require('prom-client');
const gcStats = require('prometheus-gc-stats');

prometheus.collectDefaultMetrics();
const startGcStats = gcStats(prometheus.register); // gcStats() would have the same effect in this case
startGcStats();
```

### `gc-stats`

The module doing the GC stats collecting is [`gc-stats`](https://github.com/dainis/node-gcstats). This module requires native dependencies.
If the stats don't show up, make sure to check `npm`'s install log for failures.

## 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 startGcStats = gcStats(prometheus.register, {
  prefix: 'my_application_',
});
```

## Credits

Thanks to @tcolgate for the original implementation.

[circle-ci-url]: https://circleci.com/gh/SimenB/node-prometheus-gc-stats
[circle-ci-image]: https://circleci.com/gh/SimenB/node-prometheus-gc-stats/tree/main.svg?style=shield&circle-token=05b6e173edee3b1494b0370d5d3caea00ad358a3
[npm-url]: https://npmjs.org/package/prometheus-gc-stats
[npm-image]: https://img.shields.io/npm/v/prometheus-gc-stats.svg

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