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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rabbit-company/openmetrics-client

v2.0.1

Published

OpenMetrics client

Readme

OpenMetrics-Compatible Metrics Library

JSR npm version TypeScript

A production-ready, type-safe implementation of OpenMetrics standard for Node.js / Deno / Bun applications with zero dependencies.

Features

  • 100% OpenMetrics Compliance - Fully implements OpenMetrics specification with proper content-type headers
  • TypeScript First - Complete type definitions and generics support
  • Comprehensive Metric Types:
    • 🔢 Counters - Monotonically increasing values
    • 📊 Gauges - Arbitrary up/down values
    • ⏱️ Histograms - Bucketed observations with configurable buckets
    • 📈 Summaries - Sliding window quantiles
    • ℹ️ Info - Static metadata (always value=1)
    • 🗂️ StateSets - Mutually exclusive states (like enums)
    • Unknown - Special cases (use sparingly)
  • Automatic Registry Management - Optional auto-registration
  • Label Support - Multi-dimensional metrics with proper escaping
  • Time-Based Windowing - Configurable observation windows for summaries

Installation

npm install @rabbit-company/openmetrics-client
# or
yarn add @rabbit-company/openmetrics-client

Quick Start

import { Registry, Counter, Gauge, Histogram } from "@rabbit-company/openmetrics-client";

// 1. Create registry (singleton recommended)
const registry = new Registry({
	prefix: "myapp", // Optional metric prefix
});

// 2. Define metrics
const httpRequests = new Counter({
	name: "http_requests_total",
	help: "Total HTTP requests",
	labelNames: ["method", "status"],
	registry,
});

const tempGauge = new Gauge({
	name: "temperature_celsius",
	help: "Current temperature",
	unit: "celsius",
	labelNames: ["location"],
	registry,
});

// 3. Record metrics
httpRequests.labels({ method: "GET", status: "200" }).inc();
tempGauge.labels({ location: "server_room" }).set(23.5);

// 4. Expose metrics endpoint
import express from "express";
const app = express();

app.get("/metrics", (req, res) => {
	res.set("Content-Type", Registry.contentType).send(registry.metricsText());
});

app.listen(8080);

Metric Types Guide

📈 Counter (monotonically increasing)

const counter = new Counter({
	name: "login_attempts_total",
	help: "Total user login attempts",
	labelNames: ["result"], // Optional labels
	registry,
});

// Usage:
counter.labels({ result: "success" }).inc(); // +1
counter.labels({ result: "success" }).inc(5); // +5

🔢 Gauge (arbitrary values)

const gauge = new Gauge({
	name: "memory_usage_bytes",
	help: "Current memory usage",
	unit: "bytes", // Recommended for units
	registry,
});

// Usage:
gauge.set(512 * 1024 * 1024); // Absolute value
gauge.inc(100); // Increase
gauge.dec(50); // Decrease

⏱️ Histogram (bucketed observations)

const histogram = new Histogram({
	name: "http_request_duration_seconds",
	help: "Request duration distribution",
	buckets: [0.1, 0.5, 1, 2.5, 5, 10], // Custom buckets
	registry,
});

// Usage:
histogram.observe(1.23); // Record duration

⚖️ GaugeHistogram (current distribution)

const requestSizes = new GaugeHistogram({
	name: "http_request_size_bytes",
	help: "Current request size distribution",
	buckets: [100, 500, 1000, 5000],
	unit: "bytes",
	registry,
});

requestSizes.observe(450); // Falls in 500 bucket
requestSizes.observe(1200); // Falls in 5000 bucket

📊 Summary (quantiles over sliding window)

const summary = new Summary({
	name: "database_query_duration",
	help: "Query performance quantiles",
	quantiles: [0.5, 0.9, 0.99], // Default quantiles
	maxAgeSeconds: 300, // 5 minute window
	ageBuckets: 5, // Number of buckets
	registry,
});

// Usage:
summary.observe(0.42);

🗂️ StateSet (mutually exclusive states)

const serviceState = new StateSet({
	name: "service_status",
	help: "Current service state",
	states: ["starting", "running", "degraded", "stopped"],
	labelNames: ["instance"], // Optional labels
	registry,
});

// Usage:
serviceState.labels({ instance: "api-1" }).enableOnly("running");

ℹ️ Info (static metadata)

const buildInfo = new Info({
	name: "build_info",
	help: "Build information",
	labelNames: ["version", "commit", "env"],
	registry,
});

buildInfo
	.labels({
		version: "1.2.3",
		commit: "abc123",
		env: process.env.NODE_ENV,
	})
	.set();

❓ Unknown (special cases)

const specialMetric = new Unknown({
	name: "custom_metric",
	help: "Special non-standard metric",
	registry,
});

specialMetric.set(42);