npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@refpool/metrics

v0.1.0

Published

Prometheus and OpenTelemetry metric exporters for @refpool/core pools, plus a ready-to-import Grafana dashboard.

Readme

@refpool/metrics

Prometheus and OpenTelemetry metric exporters for @refpool/core pools, plus a ready-to-import Grafana dashboard.

Both binders subscribe to the pool's typed events and sample getStats(), so you get saturation, hit rate, in-flight waiters, and live circuit-breaker state with one line of wiring.

Install

npm install @refpool/metrics
# plus whichever exporter you use:
npm install prom-client            # for the Prometheus binding
npm install @opentelemetry/api     # for the OpenTelemetry binding

Both peers are optional, because the two exporters live on independent subpaths — install only the one you use:

| Subpath | Required peer | | --- | --- | | @refpool/metrics/prometheus | prom-client | | @refpool/metrics/opentelemetry | @opentelemetry/api |

The Prometheus binding loads prom-client lazily, so importing @refpool/metrics/prometheus without it installed does not crash on import — bindPrometheus() throws a clear install prom-client to use the Prometheus exporter error only if you actually call it. The OpenTelemetry binding takes a Meter you supply, so it never hard-requires @opentelemetry/api at runtime.

Metric names

All metrics are prefixed refpool_ by default (override via prefix).

| Metric | Type | Meaning | | --- | --- | --- | | refpool_live | gauge | Undisposed resources (live pool + held orphans). | | refpool_idle | gauge | Live resources at refcount 0 (reclaimable). | | refpool_in_use | gauge | Live resources with at least one holder. | | refpool_keys | gauge | Distinct keys held in the live pool. | | refpool_waiters | gauge | Acquire calls blocked on resource creation. | | refpool_max | gauge | Configured upper bound on live keyed resources. | | refpool_saturation_ratio | gauge | Pool saturation as live / max (0..1). | | refpool_breaker_state | gauge | Current breaker state (0=closed, 1=half-open, 2=open). | | refpool_created_total | counter | Resources created. | | refpool_disposed_total | counter | Resources disposed. | | refpool_evicted_total | counter | Resources evicted (lru/ttl/drain). | | refpool_hits_total | counter | Acquire cache hits. | | refpool_misses_total | counter | Acquire cache misses. | | refpool_acquires_total | counter | Acquire handles checked out. | | refpool_releases_total | counter | Holder references released. | | refpool_breaker_transitions_total | counter | Breaker transitions, labeled by state. |

The core pool does not surface its max publicly — pass the same max you gave the pool so the saturation ratio is meaningful.

Prometheus

import { RefCountedLruPool } from '@refpool/core';
import { bindPrometheus } from '@refpool/metrics/prometheus';
import express from 'express';

const pool = new RefCountedLruPool({ max: 50, factory });
const binding = bindPrometheus(pool, { max: 50, labels: { pool: 'tenant-db' } });

const app = express();
app.get('/metrics', async (_req, res) => {
  res.set('Content-Type', binding.contentType);
  res.end(await binding.metrics());
});

// on shutdown: binding.unbind();

bindPrometheus(pool, options) returns { registry, contentType, metrics(), unbind(), dispose() }. Options: registry?, prefix?, max?, labels?.

OpenTelemetry

import { metrics } from '@opentelemetry/api';
import { bindOpenTelemetry } from '@refpool/metrics/opentelemetry';

const meter = metrics.getMeter('refpool');
const binding = bindOpenTelemetry(pool, { meter, max: 50, attributes: { pool: 'tenant-db' } });

// on shutdown: binding.unbind();

bindOpenTelemetry(pool, options) returns { unbind(), dispose() }. Options: meter (required), prefix?, max?, attributes?.

Grafana

A pre-built dashboard (saturation, hit rate, breaker state, RSS trend) lives at grafana/refpool-dashboard.json in the repo. Import it into Grafana and point it at your Prometheus data source.

Exports

| Subpath | Provides | | --- | --- | | @refpool/metrics | bindPrometheus, bindOpenTelemetry, BREAKER_STATE_CODE, DEFAULT_PREFIX, types | | @refpool/metrics/prometheus | bindPrometheus + Prometheus types | | @refpool/metrics/opentelemetry | bindOpenTelemetry + OpenTelemetry types |

License

MIT © Atul Singh