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

watchdog-express

v0.0.5

Published

Simple express monitoring middleware

Downloads

2

Readme

THIS IS IN THE PRE-ALPHA, DO NOT USE THIS / DONT EVENT THINK ABOUT USING THIS IN PRODUCTION

watchdog-express

The super awesome monitoring middleware and API for any kind of NodeJS services

watchdog-express is currently really unstable, so you should not use or plan this in production for the next months, it wont even make sence to install because the whole api will change with time till 1.0.0

Installation watchdog-express is super simple to integrate in an existing express application, just follow the steps.

npm install watchdog-express

After install, just add the following lines of code to your express app instance

const watchdogExpress = require('watchdog-express').watchdog
// app = express() ...

const watchdog = new watchdogExpress({
	allowRequestParams: true
})

app.post('/your-custom-route', watchdog.middleware()}

//app.listen(...)

Now your express app should start without errors, if not just stop reading here and leave the page and come back in one month ^^

Configuration The configuration can be made in two diffrent ways

  1. Configuration hardcoded inside your express application

  2. Via request body

  3. Hard-Coded way You have to pass the configuration while initializing the watchdog instance as followed. In this example i will enable the cpu-check check and set custom alerting values

     const watchdogExpress = require('watchdog-express').watchdog
     // app = express() ...
    	
     const watchdog = new watchdogExpress({
     	allowRequestParams: false,
     		'cpu-check': {
     			'dangerous': 90,
     			'warning': 80
     		}
     })
    	
     app.post('/your-custom-route', watchdog.middleware()}
    
     //app.listen(...)

As you can see, i have disabled the allowRequestParams flag. This will prevent using the Body request way im describing right now

  1. Body request way

In mose of the cases you are going to check the values by making a REST call to the uri. By making this call you can pass arguments to get only the data you need.

My app.js will look like the following, please make sure to enabled the allowRequestParams and the watchdog route is listening on post. Its also required to use and install body-parser, as described below.

    const watchdogExpress = require('watchdog-express').watchdog
    const bodyParser = require('body-parser')
    // app = express() ...

	app.use(bodyParser.json())
	
	const watchdog = new watchdogExpress({
		allowRequestParams: true
	})
	
	app.post('/your-custom-route', watchdog.middleware()}

	//app.listen(...)

Now use a rest client, postman for example to make the following Request method => post url => /your-custom-route body ( JSON ) =>

{
	"config": {
		"cpu-check": {
			"warning": 80,
			"dangerous": 90
		}
	}
}

You can pass all the configuration formatted in JSON to the "config": key.

Wow, thats verry much so far, lets have a look to the response

In both methods we should get the same response

{
    "cpu-check": {
        "status": 0,
        "level": 0,
        "data": {
            "load": 34.070796460176986,
            "user": 27.43362831858407,
            "system": 6.637168141592921
        },
        "messages": []
    }
}

As we can see, everything is okey.