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

rust-node-monitor

v0.2.0

Published

Lightweight Node.js monitoring powered by Rust.

Readme

rust-node-monitor

Lightweight Node.js monitoring powered by Rust.

rust-node-monitor is a lightweight monitor for Node.js applications with a core written in Rust, built to collect process metrics — and, in upcoming releases, HTTP metrics — with very low overhead.

It ships as a prebuilt native addon (via napi-rs), so there is no compiler required at install time on supported platforms.

CI npm node license

🌐 Website: rust-node-monitor.vercel.app


Installation

npm install rust-node-monitor

Works with both ESM and CommonJS, and requires Node.js 18+.


Quick start

import { snapshot } from "rust-node-monitor";

console.log(snapshot());
// CommonJS
const { snapshot } = require("rust-node-monitor");
console.log(snapshot());

Example output:

{
  pid: 12345,
  cpuPercent: 12.5,
  memoryRss: 84520960,
  memoryVirtual: 312000000,
  threads: 8,
  uptimeSeconds: 3600,
  timestamp: 1710000000
}

API

hello(): string

A sanity check that confirms the native addon loaded correctly. Returns "Hello from Rust".

import { hello } from "rust-node-monitor";
console.log(hello()); // "Hello from Rust"

snapshot(): Snapshot

Collects a point-in-time snapshot of the current process.

import { snapshot } from "rust-node-monitor";

const metrics = snapshot();
console.log(metrics.pid);
console.log(metrics.memoryRss);
console.log(metrics.cpuPercent);

| Field | Type | Description | | ---------------- | -------- | ------------------------------------------------------ | | pid | number | Process ID | | cpuPercent | number | Process CPU usage (%). See the CPU note below | | memoryRss | number | Resident set size, in bytes | | memoryVirtual | number | Virtual memory, in bytes | | threads | number | OS thread count (best-effort per platform) | | uptimeSeconds | number | Seconds since the process started | | timestamp | number | Unix timestamp (seconds) at collection time |

CPU note: A single snapshot() call may report cpuPercent: 0. CPU usage requires two samples spaced over time to compute a delta, and an isolated call has no interval to compare against. For continuous, reliable CPU use the Monitor class.

Monitor

A continuous process monitor. Unlike snapshot(), it computes cpuPercent reliably by accumulating process CPU time between samples and dividing by the real elapsed time (aggregated across all cores — it can exceed 100% under multi-threaded load).

import { Monitor } from "rust-node-monitor";

const monitor = new Monitor({
  intervalMs: 1000,
  collectCpu: true,
  collectMemory: true,
});

monitor.start();

setInterval(() => {
  console.log(monitor.stats());
}, 1000);

// later…
monitor.stop();

monitor.stats() returns a Snapshot plus a samples counter. The internal timer is unref'd, so it will not keep your process alive on its own.

prometheus(stats?): string

Renders a snapshot in the Prometheus text exposition format.

import express from "express";
import { prometheus, Monitor } from "rust-node-monitor";

const monitor = new Monitor().start();
const app = express();

app.get("/metrics", (_req, res) => {
  res.type("text/plain").send(prometheus(monitor.stats()));
});

checkAlerts(thresholds, stats?): Alert[]

Simple, stateless threshold alerts over the process metrics. Pass the thresholds you want to watch; it returns the alerts that fired (a metric exceeds its threshold). Only the thresholds you provide are evaluated.

import { Monitor, checkAlerts } from "rust-node-monitor";

const monitor = new Monitor().start();

setInterval(() => {
  const fired = checkAlerts(
    { cpuPercent: 80, memoryRssBytes: 500_000_000 },
    monitor.stats(), // pass stats for reliable CPU; defaults to snapshot()
  );
  for (const alert of fired) {
    console.warn(`[alert] ${alert.metric}=${alert.value} > ${alert.threshold}`);
  }
}, 5000);

Each Alert is { metric, value, threshold, severity: "warning" }, where metric is one of "cpuPercent", "memoryRssBytes", "memoryVirtualBytes". Being stateless, you decide when to evaluate and what to do with the result (log, page, open an incident, forward to ImmutableLog…).


Framework integrations

These subpath imports record per-request latency and error counts into a shared collector (or one you provide). The framework packages are optional peer dependencies — install only what you use.

Express

import express from "express";
import { monitorMiddleware, getRequestMetrics } from "rust-node-monitor/express";

const app = express();
app.use(monitorMiddleware());

app.get("/health", (_req, res) => res.json({ ok: true }));
app.get("/stats", (_req, res) => res.json(getRequestMetrics()));

Fastify

import Fastify from "fastify";
import { monitorPlugin } from "rust-node-monitor/fastify";

const fastify = Fastify();
fastify.register(monitorPlugin);

NestJS

import { RustNodeMonitorInterceptor } from "rust-node-monitor/nestjs";

// In main.ts
app.useGlobalInterceptors(new RustNodeMonitorInterceptor());

Supported platforms

Prebuilt binaries are published for:

| OS | Architecture | Triple | | ------- | ------------ | ---------------------------- | | macOS | arm64 | aarch64-apple-darwin | | macOS | x64 | x86_64-apple-darwin | | Linux | x64 (glibc) | x86_64-unknown-linux-gnu | | Linux | arm64 (glibc)| aarch64-unknown-linux-gnu | | Windows | x64 | x86_64-pc-windows-msvc |


How it works

┌──────────────────────────┐     ┌───────────────────────────┐
│  Your Node.js app (TS/JS)│────▶│  rust-node-monitor (JS API)│
└──────────────────────────┘     │  Monitor, prometheus, …    │
                                  └─────────────┬──────────────┘
                                                │ N-API (napi-rs)
                                  ┌─────────────▼──────────────┐
                                  │  Rust core (.node addon)   │
                                  │  snapshot(), hello()       │
                                  │  sysinfo + platform calls  │
                                  └────────────────────────────┘

The native core is built with napi-rs: the #[napi] macro generates the glue that registers Rust functions as ordinary JavaScript functions. snake_case field names become camelCase in JS automatically, and TypeScript types are generated into binding.d.ts.


Limitations (v0.1.0)

  • snapshot() reports cpuPercent: 0 on the first call — use Monitor for continuous CPU.
  • threads is collected via /proc on Linux and Mach APIs on macOS. On other platforms it returns 0 for now (planned for v0.2.0).
  • Metrics are scoped to the current process (no child-process aggregation yet).

Roadmap

Shipped in v0.2.0

  • ✅ Simple threshold alerts (high CPU, high memory) via checkAlerts(...).

Planned

  • 🔜 Event loop delay tracking (and a "stalled loop" alert).
  • 🔜 Full request metrics (total, errors, latency avg/p95/p99) wired natively.
  • 🔜 First-class Prometheus exporter helpers per framework.
  • 🔜 Windows thread count.
  • 🔜 Optional integration with ImmutableLog for health/audit events.

Development

# install dependencies
npm install

# build the native addon (Rust) + the TypeScript layer
npm run build

# run tests
npm test

See docs/PASSO-A-PASSO.md for a full, step-by-step build log (in Portuguese) explaining the Rust and napi-rs details.


License

MIT © Roberto Lima