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

monitr

v1.2.3

Published

Node process monitoring tool

Downloads

140

Readme

monitr

Nodejs process monitoring module

This package is tested only with Node.js LTS versions.

Note: This module currently works only on Linux operating systems.

External statistics reporting

This module starts a separate thread within the Nodejs runtime that monitors and collects statistics about the running nodejs process. These statistics are then sent as JSON messages via UDP datagrams over a local domain socket.

Here is the list of data the module reports periodically:

 { status:
     { pid: <pid of the node process>,
       ts: <current time stamp>,
       cluster: <process group id>,
       reqstotal: <total requests processed by this node process server>,
       utcstart: <when the process was started>,
       events: <number of new reports being processed since last stats reporting>,,
       cpu: <cpu usage>,
       mem: <memory usage>,
       cpuperreq: <cpu usage per request>,
       oreqs: <current open requests count>,
       sys_cpu: <system cpu load>,
       oconns: <current open connections count>,
       user_cpu: <user cpu load>,
       rps: <requests per second>,
       kbs_out: <kbs of data transferred since last stats reporting>,
       elapsed: <time elapsed since last event>,
       kb_trans: <total kbs of data transferred>,
       jiffyperreq: <cpu usage in terms of ticks per request>,
       gc: {
           scavenge: { count: <number>, elapsed_ms: <number>, max_ms: <number> },
           marksweep: { count: <number>, elapsed_ms: <number>, max_ms: <number> }
       }
    }
 }

GC introspection

It provides the running nodejs application with the ability to introspect garbage collection activity by creating read-only properties at process.monitor.gc that reports:

  1. count: number of times GC stop-the-world events occurred
  2. elapsed: cumulative time (in milliseconds) spent in GC

Installation

With npm do:

npm install monitr

Usage

var monitor = require('monitr');

start()

monitor.start();

Spawns a thread and monitors the process. Writes process stats every second to the socket path.

stop()

monitor.stop();

Terminates the thread and closes the socket.

setIpcMonitorPath(socketPath)

monitor.setIpcMonitorPath('/tmp/my-process-stats.mon');

Sets the datagram socket name to write the stats. Defaults to /tmp/nodejs.mon

Health Status

Monitr supports custom health functionality whereby the app can report its own health. The following methods are added to process.monitor to set and get the health information.

setHealthStatus(isDown, statusCode)
isDown()
getStatusCode()
getStatusTimestamp() - Return seconds when setHealthStatus was last called
getStatusDate() - Return Date object

Once setHealthStatus is invoked, the status json, described above, will have following additional fields.

health_status_timestamp: <timestamp when the setHealthStatus was invoked, in sec>,
health_is_down: <app is down or up, boolean>,
health_status_code: <health status code>

Handling HUP events

Monitr installs a custom SIGHUP handler which will optionally print out a NodeJS stack backtrace of the Javascript currently being executed. This can be useful for debugging where a NodeJS process may be stuck.

Implementation

It looks up /proc/* files on the system to report CPU Usage. It looks up /proc/pid/* files on the system to report its own stats. process.monitor.* methods are set by lib/monitor.js.

It calls the process.monitor.* methods to report total requests since monitoring started (reqstotal), current requests in flight (oreqs), current open connections (oconns) and total data returned since monitoring started (kb_trans). Note: oreqs may be greater than oconns when keepalive is enabled.

It attaches to the v8 garbage collection hooks to instrument (for each GC type) the following stats for each reporting interval.

  1. count : number of times GC type invoked
  2. elapsed_ms: total elapsed time nodejs thread is blocked
  3. max_ms: maximum time spent blocked by any one GC event

Example

Please refer to examples/README.md for examples showing the use of these functions.

Build Status

Build Status

Node Badge

NPM