express-monitoring
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Express Monitoring

codecov Build Status

Package allows to define custom monitoring controls (rules) and execute them using express handlers.

This NodeJS adaptation of Horat1us/yii2-monitoring package for PHP.

Written on Typescript.

Installation

Using NPM:

npm i express-monitoring

Documentation

Structure

  • Controller - controller with express request handlers
  • Control - interface for monitoring control items.
    • Compose - pre-defined control to compose another controls.
    • Dependency - pre-defined control to block execution of another control.
  • FailureError - error class to be thrown in controls.

Usage

You need to define your own Control or use one of pre-defined. Then, just create Controller instance and add it to routes.

// region Monitoring Controller Definition
// This should be placed to separate file
import * as monitoring from "express-monitoring";
 
// can also be async or return promise
const SomeControl: monitoring.Control = () => {
    // check for something
    const isSuccessful = false;
    
    if (!isSuccessful) {
        throw new monitoring.FailureError(
            "Something goes wrong.",
            0, // error code
            {}, // details, optional
            "NotSuccessful" // string error type
        );
    }
    
    return {}; // you also may return details
};
 
let controls = {
    "controlID": SomeControl, 
};
const Monitoring = new monitoring.Controller(controls);
// endregion
 
import * as express from "express";
 
const app = express();
const port = 3000;
 
app.get('/monitoring/:id', Monitoring.control); // route to check controls separately
app.get('/monitoring/full', Monitoring.full); // route to check all controls by one request
 
 
app.listen(3000, () => `Monitoring app listening on port ${port}`);

Then you can make request GET http://localhost:3000/monitoring/controlID. For response examples see Documentation.

License

MIT

Package Sidebar

Install

npm i express-monitoring

Weekly Downloads

11

Version

1.0.1

License

MIT

Unpacked Size

25.6 kB

Total Files

31

Last publish

Collaborators

  • horat1us