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

memtracker

v1.0.0

Published

A lightweight Node.js module for tracking memory usage of in-process data structures, with system resource monitoring and adaptive pressure detection.

Readme

memTracker

A lightweight Node.js module for tracking memory usage of in-process data structures, with system resource monitoring and adaptive pressure detection.

Features

  • Track any data structure - Register Maps, Sets, Arrays, Objects and get periodic reports on their type, count and estimated memory size.
  • System monitoring - Polls CPU usage, load average, memory and uptime at a configurable interval.
  • Adaptive pressure detection - Computes a pressure score from CPU and memory usage, with hysteresis-based level transitions (LOW / NORMAL / HIGH / CRITICAL) to avoid flapping.
  • Pressure callbacks - Get notified when the system pressure level changes.
  • File reports - Optionally save JSON reports to disk, with rotation support.
  • Non-blocking - All timers use .unref() so the tracker never prevents your process from exiting.

Requirements

Node.js >= 14.0.0

Installation

npm install memtracker

Quick start

const MemTracker = require('memtracker');

const tracker = new MemTracker({
    reportInterval: 30000,
    logLevels: ['HIGH', 'CRITICAL'],
    log: { status: 'prettyJson' },
    autoStart: true
});

// Register data structures to track
const myCache = new Map();
tracker.register('myCache', () => myCache);

// Later, stop everything
tracker.stop();

API

new MemTracker(options?)

Creates a new tracker instance. Nothing starts until you call start(), unless autoStart is set to true.

| Option | Type | Default | Description | |--------|------|---------|-------------| | reportInterval | number | 60000 | How often (ms) to generate a memory report. | | logLevels | string[] | ['HIGH', 'CRITICAL'] | Pressure levels at which the heap summary line is logged to console. | | log.status | string | — | Console output format: 'table', 'json' or 'prettyJson'. Omit to disable console output of the entries table. | | log.path | string | — | Directory path to save JSON report files. Omit to disable file output. | | log.rotate.enabled | boolean | false | Enable report file rotation. | | log.rotate.keep | number | 10 | Number of rotated report files to keep. | | autoStart | boolean | false | Start tracking immediately on construction (no need to call start()). | | system.pollInterval | number | 5000 | How often (ms) to poll CPU, memory and uptime. | | system.logPressureChanges | boolean | false | Log pressure level transitions to the console. |

tracker.start()

Starts the system monitor and the periodic report interval.

tracker.stop()

Stops all timers (report interval and system polling).

tracker.register(name, getter)

Register a named data structure to track.

  • name — A string identifier for the entry.
  • getter — A function that returns the value to measure. Called on each report cycle.
tracker.register('sessions', () => sessionStore);
tracker.register('requestQueue', () => queue);

tracker.unregister(name)

Remove a previously registered entry by name.

tracker.report()

Manually trigger a report (normally called automatically by the interval).

tracker.onPressureChange(callback)

Register a callback that fires when the system pressure level changes.

tracker.onPressureChange((level, score) => {
    console.log(`Pressure is now ${level} (score: ${score})`);
    if (level === 'CRITICAL') {
        // shed load, clear caches, etc.
    }
});

tracker.systemInfo

Read-only property returning the current system snapshot:

{
    cpu: { usage: 42.5, loadAvg: [1.2, 0.8, 0.6] },
    memory: { free: 4000000000, freePct: 0.25, total: 16000000000, used: 12000000000, usedPct: 75.0 },
    pressure: { score: 55.1, level: 'NORMAL', prevLevel: 'LOW', levelSince: 1700000000000 },
    uptime: 3600
}

Pressure levels

The pressure score is a weighted average of CPU usage (60%) and memory usage (40%), smoothed over a 2-minute sliding window. Level transitions use hysteresis thresholds to prevent rapid flapping:

| Level | Transitions up | Transitions down | |-------|---------------|-----------------| | LOW | NORMAL >= 25, HIGH >= 60, CRITICAL >= 85 | — | | NORMAL | HIGH >= 60, CRITICAL >= 85 | LOW < 20 | | HIGH | CRITICAL >= 85 | LOW < 20, NORMAL < 50 | | CRITICAL | — | NORMAL < 50, HIGH < 75 |

Full example

const MemTracker = require('memtracker');

const tracker = new MemTracker({
    reportInterval: 30000,
    logLevels: ['HIGH', 'CRITICAL'],
    log: {
        status: 'prettyJson',
        path: './logs/',
        rotate: { enabled: true, keep: 5 }
    },
    system: {
        pollInterval: 5000,
        logPressureChanges: true
    }
});

const users = new Map();
const eventQueue = [];

tracker.register('users', () => users);
tracker.register('eventQueue', () => eventQueue);

tracker.onPressureChange((level, score) => {
    if (level === 'CRITICAL') {
        eventQueue.length = 0; // emergency flush
    }
});

tracker.start();

// On graceful shutdown
process.on('SIGTERM', () => {
    tracker.stop();
    process.exit(0);
});

License

ISC