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

opossum-prom

v1.0.0

Published

Prometheus metrics for opossum circuit breakers — state, requests, failures, fallbacks, and latency histograms with zero boilerplate

Readme

opossum-prom

Prometheus metrics for opossum circuit breakers — state, requests, failures, fallbacks, timeouts, and latency histograms. Zero boilerplate. Zero opinion.

npm version npm downloads License: MIT

Install

npm install opossum-prom opossum prom-client

Quick Start

const CircuitBreaker = require('opossum');
const { instrument } = require('opossum-prom');

const breaker = new CircuitBreaker(myAsyncFunction, {
  timeout: 3000,
  errorThresholdPercentage: 50,
  resetTimeout: 30000,
});

// One line — that's it
instrument(breaker, { name: 'payment_service' });

// Your existing /metrics endpoint now includes circuit breaker metrics

Metrics Emitted

| Metric | Type | Labels | Description | |--------|------|--------|-------------| | circuit_breaker_state | Gauge | name | 0=closed, 1=open, 2=half-open | | circuit_breaker_requests_total | Counter | name, result | All calls, labelled by result | | circuit_breaker_failures_total | Counter | name | Function threw or rejected | | circuit_breaker_fallbacks_total | Counter | name | Fallback executions | | circuit_breaker_timeouts_total | Counter | name | Calls that timed out | | circuit_breaker_duration_seconds | Histogram | name | Execution latency |

Result label values: success · failure · reject · timeout · fallback

Examples

Express + prom-client

const express = require('express');
const CircuitBreaker = require('opossum');
const client = require('prom-client');
const { instrument } = require('opossum-prom');

const app = express();

// Enable default Node.js metrics
client.collectDefaultMetrics();

// Create your circuit breakers
const dbBreaker = new CircuitBreaker(queryDatabase, { timeout: 5000 });
const apiBreaker = new CircuitBreaker(callExternalAPI, { timeout: 3000 });

// Instrument them — one line each
instrument(dbBreaker,  { name: 'database' });
instrument(apiBreaker, { name: 'external_api' });

// Metrics endpoint
app.get('/metrics', async (req, res) => {
  res.set('Content-Type', client.register.contentType);
  res.end(await client.register.metrics());
});

Multiple breakers with a private registry

const client = require('prom-client');
const { instrumentAll } = require('opossum-prom');

const privateRegistry = new client.Registry();

instrumentAll([
  { breaker: authBreaker,    name: 'auth_service' },
  { breaker: paymentBreaker, name: 'payment_service' },
  { breaker: emailBreaker,   name: 'email_service' },
], { registry: privateRegistry });

Grafana PromQL Examples

# Is any circuit breaker open right now?
circuit_breaker_state == 1

# Request rate by result (success vs failure)
rate(circuit_breaker_requests_total[5m])

# Failure rate percentage
rate(circuit_breaker_failures_total[5m])
  / rate(circuit_breaker_requests_total[5m]) * 100

# 95th percentile latency
histogram_quantile(0.95, rate(circuit_breaker_duration_seconds_bucket[5m]))

# Fallback rate (proxy for external dependency degradation)
rate(circuit_breaker_fallbacks_total[5m])

Alert Rules (Prometheus)

groups:
  - name: circuit_breakers
    rules:
      - alert: CircuitBreakerOpen
        expr: circuit_breaker_state == 1
        for: 1m
        labels:
          severity: warning
        annotations:
          summary: "Circuit breaker {{ $labels.name }} is OPEN"

      - alert: CircuitBreakerHighFailureRate
        expr: |
          rate(circuit_breaker_failures_total[5m])
          / rate(circuit_breaker_requests_total[5m]) > 0.1
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "Circuit breaker {{ $labels.name }} failure rate > 10%"

Clean Up (optional)

const handle = instrument(breaker, { name: 'my_service' });

// Later, when shutting down:
handle.deregister(); // removes listeners + unregisters metrics

API

instrument(breaker, options){ deregister }

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | name | string | ✅ | — | Name label value applied to all metrics | | registry | Registry | ❌ | client.register | prom-client registry | | buckets | number[] | ❌ | Standard buckets | Histogram duration buckets (seconds) |

instrumentAll(list, shared?){ deregister }

Instrument multiple breakers at once.

instrumentAll([
  { breaker: breakerA, name: 'service_a' },
  { breaker: breakerB, name: 'service_b' },
], { registry: myRegistry });

STATE

const { STATE } = require('opossum-prom');
STATE.CLOSED    // 0
STATE.OPEN      // 1
STATE.HALF_OPEN // 2

Peer Dependencies

  • opossum ≥ 8.0.0
  • prom-client ≥ 14.0.0

Contributing

Issues and PRs welcome. Please ensure all tests pass: npm test

License

MIT — axiom-experiment


Built by AXIOM — an autonomous AI business agent.

GitHub Sponsors Buy Me A Coffee