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 🙏

© 2024 – Pkg Stats / Ryan Hefner

als-performance-monitor

v0.5.11

Published

Monitor performance and overhead with real-time system metrics watchdog (cpu,ram,rss,swap).

Downloads

29

Readme

als-performance-monitor

The als-performance-monitor module offers an efficient performance monitoring tool tailored for Node.js applications. It encompasses a versatile suite of modules that track and oversee system-level performance metrics including CPU usage, RAM, RSS, and Swap memory.

Installation

npm install als-performance-monitor

Quick Start

To get started with als-performance-monitor, follow the example below:

const PM = require('als-performance-monitor');

const preferences = {
   cpu: 0.8,           // Monitor CPU, set max threshold at 80%
   ram: 0.7,           // Monitor RAM, set max threshold at 70%
   rss: 500,           // Monitor RSS, set max threshold at 500MB
   swap: 0.5,          // Monitor Swap, set max threshold at 50% (checked once per minute)
   timesInMinute: 60,  // Specify frequency of checks and logs per minute
   errorThreshold: 20  // Reset pm.errors after this number of unique errors
};

const pm = new PM(preferences);

// Registering Events
pm.emitter.on('overload', () => console.log('Overloaded event'));  // Triggered when overloaded (only when watching)
pm.emitter.on('backToNormal', () => console.log('Back to normal event'));  // Triggered when returning to normal state (only when watching)
pm.emitter.on('next', logs => console.log(logs));  // Invoked on every measurement
pm.emitter.on('error', (error, pmObj) => {  // Invoked on every unique error occurrence
   console.error(error.message);
   if (pmObj.errors.length > 20) pmObj.stop();
});

pm.run();      // Start the monitor
pm.watch();    // Start the monitor with overload tracking (enables related events)

// Check if any module is overloaded
if (pm.overloaded()) {
   console.log('System Overloaded');
}

pm.stop();   // Stops the monitor
pm.avg();    // Returns average values for the last set duration
pm.errors;   // Retrieves the last 20 errors for all modules

Note: The overloaded method determines overload based on averages, not current performance values.

Note: pm.emitter is an instance of als-event-emitter and supports methods like: on, off, has, once, etc.

Using Hooks

Providing both onOverload and onBackToNormal hooks as parameters prompts the monitor to check for overload at each interval. It will invoke the onOverload function upon detecting an overload and the onBackToNormal function once it returns to a normal state.