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

connect-middleware-monitor

v1.0.3

Published

Connect middleware to monitor an application process.

Downloads

6

Readme

Monitor

NPM version Build Status Coverage Status Dependencies

Connect middleware to monitor an application process.

Installation

$ npm install connect-middleware-monitor

Usage

To use the module,

var createMonitor = require( 'connect-middleware-monitor' );

createMonitor( [...plugin] )

The middleware generator accepts monitor plugins which append to a common metrics object.

var // Plugin which reports system metrics:
	sPlugin = require( 'monitor-plugin-os' ),

	// Plugin which reports current process metrics:
	pPlugin = require( 'monitor-plugin-process' );

// Create the monitor middleware:
var monitor = createMonitor( sPlugin, pPlugin );

Note: plugins are executed in the same order as they are provided to the middleware generator.

Each plugin should be a single method which accepts two input arguments: [object, clbk]. The object is a shared object among all plugins; hence, when choosing plugins, ensure that they are properly namespaced when appending to the object.

The callback should be invoked once the plugin finishes appending metrics. The callback takes an optional error argument. Any errors are bubbled up through the middleware.

See monitor-plugin-os and monitor-plugin-process for plugin examples.

monitor( request, response, next )

The generated middleware follows the connect middleware pattern. Monitor metrics are appended to the request object via a locals property. Hence, downstream middleware consumers may access the metrics via

var metrics = request.locals.monitor;

See the examples below.

Examples

var express = require( 'express' ),
	request = require( 'request' ),
	sPlugin = require( 'monitor-plugin-os' ),
	pPlugin = require( 'monitor-plugin-process' ),
	createMonitor = require( 'connect-middleware-monitor' );

// Define a port:
var PORT = 7331;

// Create a new monitor:
var monitor = createMonitor( sPlugin, pPlugin );

// Create a new application:
var app = express();

// Bind a route using the monitor middleware:
app.get( '/', [ monitor, sendJSON ] );

// Spin up a new server:
var server = app.listen( PORT, onListen );


function onListen() {
	request({
		'method': 'GET',
		'uri': 'http://127.0.0.1:' + PORT
	}, onResponse );
}

function onResponse( error, response, body ) {
	if ( error ) {
		throw new Error( error );
	}
	console.log( body );
}

function sendJSON( request, response, next ) {
	response
		.status( 200 )
		.send( JSON.stringify( request.locals.monitor ) );
}

To run an example from the top-level application directory,

$ node ./examples/index.js

Plugins

List of monitor plugins:

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.


Copyright

Copyright © 2014. Athan Reines.