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

senderwolf-metrics

v1.0.0

Published

Auto-instruments the SMTPConnectionPool and exports statistics (active connections, pooled bytes, failed deliveries) for senderwolf

Readme

@senderwolf/plugin-metrics

Auto-instruments the SMTPConnectionPool and exports live statistics — active connections, pooled bytes, failed deliveries — via JSON and Prometheus-compatible HTTP endpoints.

Zero external dependencies. Uses only Node.js built-ins.


Installation

npm install @senderwolf/plugin-metrics

Quick Start

import { sendEmail, closeAllPools, getPoolStats } from 'senderwolf';
import { SMTPConnectionPool } from 'senderwolf/lib/connectionPool.js';
import { MetricsPlugin } from '@senderwolf/plugin-metrics';

// Create and instrument a pool
const pool = new SMTPConnectionPool({ maxConnections: 5 });
const metrics = new MetricsPlugin().instrument(pool);

// Start the metrics HTTP server
await metrics.startServer(9100); // optional

// Send emails normally
await sendEmail({ smtp: { usePool: true, ... }, mail: { ... } });

// Read stats programmatically
const stats = metrics.getStats();
console.log(stats);
// {
//   activeConnections: 1,
//   idleConnections: 0,
//   queuedRequests: 0,
//   maxConnections: 5,
//   totalSent: 12,
//   failedDeliveries: 0,
//   pooledBytes: 48320,
//   uptime: 34,
//   timestamp: 1711700000000
// }

// Stop server when done
await metrics.stopServer();

HTTP Endpoints

| Endpoint | Description | |---|---| | GET /metrics | JSON snapshot of all stats | | GET /metrics/text | Prometheus text format (compatible with prometheus.yml scrape config) | | GET /health | { status: "ok", uptime: <seconds> } |

Example Prometheus scrape config

scrape_configs:
  - job_name: senderwolf
    static_configs:
      - targets: ['localhost:9100']
    metrics_path: /metrics/text

API

new MetricsPlugin()

Creates a new plugin instance.

.instrument(pool)

Monkey-patches a SMTPConnectionPool instance to intercept sends/failures. Call once, before any mail is sent. Returns this for chaining.

.getStats()MetricsStats

Returns a live stats snapshot. Fields:

| Field | Type | Description | |---|---|---| | activeConnections | number | Currently busy connections | | idleConnections | number | Connected but idle | | queuedRequests | number | Waiting for a free slot | | maxConnections | number | Pool's configured maximum | | totalSent | number | Cumulative successful sends | | failedDeliveries | number | Cumulative send failures | | pooledBytes | number | Estimated bytes sent (utf8) | | uptime | number | Seconds since construction / last reset() | | timestamp | number | Epoch ms of snapshot |

.reset()

Zeroes totalSent, failedDeliveries, pooledBytes, and resets uptime. Does not affect the pool's connection state.

.startServer(port?: number)

Starts the HTTP metrics server on the given port (default 9100). Returns a Promise<void>.

.stopServer()

Gracefully closes the HTTP server. Returns a Promise<void>.


License

MIT © Chandraprakash