Giter VIP home page Giter VIP logo

watchpuppy's Introduction

Watchpuppy ๐Ÿถ

An almost fully grown watchdog for node.js

This is a simple watchdog for node.js. It has no external dependencies and runs within the node process itself. This is not meant to replace something like an external health check service or a more advanced tool like foreverjs.

But sometimes you just need to keep an eye out on a simple worker script and make sure it is stil crunching data.

It is kept simple, i.e. there are no dependencies, just plain simple JavaScript (ES6).

Pull requests welcome.

Install

npm install watchpuppy

Usage

Simple example checking every 5 minutes and exiting the process if there weren't at least two pings:

const Watchpuppy = require('watchpuppy');

//setup watchpuppy

//defaults:
// checkInterval: 10000 (10s)
// minPing: 1
// stopOnError: true (stop the watchpuppy when a check fails)

//example:
// check every 5 minutes (checkInterval in ms)
// require at least two pings in the 5 min window
// stop checking after first error
// exit process on error

const options = {checkInterval: 5 * 60 * 1000, minPing: 1, stopOnError: true};
const callback = (err) => {
  console.error(err);
  process.exit(1);
};

const watchpuppy = new Watchpuppy(options, callback);

//fire a ping whenever you know things are running fine, e.g. somewhere in your stream processing
watchpuppy.ping();

//you can modify the weight of a ping by passing in a number
watchpuppy.ping(5); //equivalent to firing watchpuppy.ping() five times

//you can also invalidate a ping by passing in a negative number
watchpuppy.ping(-1); //doesn't do anything

Another example that doesn't stop on the first failure and simply logs errors to the console:

const Watchpuppy = require('watchpuppy');

const options = {stopOnError: false, minPing: 5};
const callback = (err) => {
  //err is a js Error with a message such as: 'only 3 pings received since last check'
  console.log(err.message);
};

const watchpuppy = new Watchpuppy(options, callback);

License

This module is licensed under the MIT license.

watchpuppy's People

Contributors

zoellner avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

amonroe

watchpuppy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.