watchdog-express

0.0.5 • Public • Published

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.

Package Sidebar

Install

npm i watchdog-express

Weekly Downloads

0

Version

0.0.5

License

ISC

Last publish

Collaborators

  • ben.ammann