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

express-performance-monitor

v0.0.1

Published

Monitoring tooling agnostic Express Application Server in-process performance monitoring middleware and agent

Downloads

4

Readme

express-performance-monitor

Monitoring tooling agnostic Express Application Server in-process performance monitoring middleware and agent

With express-monitor provides node application server developers with a flexible way of implementing service specific monitoring over a unified interface. You can monitor your current express app, internals, add new monitoring fields and extend the exposed monitoring data

Example Configuration

In this simplified example we


var Manager = require("express-performance-monitor").Manager;

var app = require("express")();

var manager = new monitor.Manager({
	maxRetention: 1000 * 60 * 5,
	aggregate: 60,
	apis: ["web"],
	server: {
		"web": {
			port: 3001,
			listen: "0.0.0.0"
		}
	});

var middleware = require("express-performance-monitor").middleware(manager);
// IMPORTANT: to make sure we see everythin add this as the first middleware in your middleware stack
app.use(middleware);

app.get("/", function(req, res) {
  res.sendStatus(200);
});

app.listen(3000, function() {
  console.log("Listening on localhost:3000");
});

Out of the box you will get statistics for:

  • CPU utilization
  • memory usage
  • request count
  • transferred bytes

for each network request sent through your express app.

Adding custom fields

The middleware will store aggregated performance data specific to the type of data you wish to collect.

Depending on the metrics you are interested in different types of aggregation can be applied. Here are a few examples we already provide:

Average aggregation

{
  "name": "memory",
  "type": "avg",
  "aggregate": 60
}

Example usage:

var pidusage = require("pidusage");
pidusage.stat(process.pid, function(err, stat) {
	if (err) {
		return;
	}
	manager.addDataPoint("memory", stat.memory);
});

Averaged over each event and collected data this will store the last minute of memory and aggregate the metric

Counter aggregation

{
  "name": "requestCount",
  "type": "count",
  "aggregate": 60
}

Example usage:

manager.addDataPoint("requestCount");

Count-style aggregation with a configuration like this will provide a counter that will reset every minute and have a histogram for the last minute of the counter.

Summized or cumulative aggregation

{
  "name": "transferredBytes",
  "type": "cumulative",
  "aggregate": 60
}

Example usage:

manager.addDataPoint("transferredBytes", data.length);

This is a special type of the Counter where the value added to the counter is not affixed to the a single increment but the value passed into the datapoint addition call.

Express Middleware

Interacting with the Manager instance during your express applications lifecycle is possible using the express Request object parameter passed into every callback.

You can find it under the req.monitor.manager object in your callback:

app.get("/status", function(req, res) {
  res.json(req.monitor.manager.getState());
});

Please review the API documentation for more information on how to interact with the Manager instance.

Integration with Monitoring Tools

Using the API Module infrastructure you are free to either use the provided API endpoint modules provided out of the box with this package or write your own module. Have a look at the lib/apis/example.js for a simple example of how to implement your own API endpoints applicable for your environment.