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

btrz-health-check

v3.0.0

Published

A series of classes that will ping different service types to verify accessibility.

Downloads

246

Readme

btrz-health-check

A series of classes that will ping different service types to verify accessibility. Used in Betterez microservices to check status of dependent services.

Runtimes supported

io.js >= 2.0.3 node >= v4.2

Usage

The main class is the HealthCheckers class.

This class exposes only one method .checkStatus() that takes an array of checkers. Each checker will check one service and returns a promise that will resolve or reject accordingly to the status of the service. The module comes with a series of checkers that you can configure and use for your particular case (see below for more information). You can also create your own checkers easily.

Custom checkers

All custom providers will return a promise that resolves or fails with the service name and status.

{name: "ServiceName", status: 200} //if promise resolves
{name: "ServiceName", status: 200} //if promise rejects

All custom providers also take an optional options parameter that allow to override the service name and to provide a logger object.

Override the service name is useful when you need to validate the connection to multiple services of the same type.

let mongoChecker = new MongoDbHealthChecker(mongoDriver, {name: "MyCustomServiceName"});

You can also provide a logger to log the error on failure. The object should have an .error function. It will be called with the name of the service and the error.

let mongoChecker = new MongoDbHealthChecker(mongoDriver, {logger: myLogger});

Build in checkers

SQS

Will check connectivity to Amazon SQS. It will read a list of queues available for the logged in user.

{name: "SQS", status: 200} //if promise resolves
{name: "SQS", status: 200} //if promise rejects

#### Usage

    let SQSHealthChecker =  require("btrz-health-checker").SQSHealthChecker;

    let sqsChecker = new SQSHealthChecker(awsSqsDriver);
    sqsChecker.checkStatus()
      .then(function (result) {
        //If's working fine
      })
      .catch(function (result) {
        //Something is not wright.
      });

The only mandatory parameter is an instance of a properly configured AWS SQS driver. Internally we will call the listQueues() function, so it should at least implement that function.

MongoDb

Will check connectivity to MongoDb doing a call to collectionNames in the MongoDb driver.

{name: "MongoDb", status: 200} //if promise resolves
{name: "MongoDb", status: 200} //if promise rejects

Usage

let MongoDbHealthChecker =  require("btrz-health-checker").MongoDbHealthChecker;

let mongoChecker = new MongoDbHealthChecker(mongoDriver);
mongoChecker.checkStatus()
  .then(function (result) {
    //If's working fine
  })
  .catch(function (result) {
    //Something is not wright.
  });

The only mandatory parameter is an instance of a properly configured mongoDriver. Internally we will call the collectionNames() function, so it should at least implement that function.

Socket

Will check connectivity to a socket server using the net module

{name: "Socket", status: 200} //if promise resolves
{name: "Socket", status: 200} //if promise rejects

Usage

let SocketHealthChecker =  require("btrz-health-checker").SocketHealthChecker;

let socketChecker = new SocketHealthChecker(mongoDriver);
socketChecker.checkStatus()
  .then(function (result) {
    //If's working fine
  })
  .catch(function (result) {
    //Something is not wright.
  });

The only mandatory parameter is a config literal with a host and port to connect to. The config can also contains a timeout property and it will be use to fail in case the timeout is reached, the default value is 5000.

Sequelize

Will check connectivity to the Sequelize DB doing a call to authenticate.

{name: "Sequelize DB", status: 200} //if promise resolves
{name: "Sequelize DB", status: 500} //if promise rejects

Usage

const SequelizeDbHealthChecker =  require("btrz-health-checker").SequelizeDbHealthChecker,
  sequelizeChecker = new SequelizeDbHealthChecker(sequelize);

sequelizeChecker.checkStatus()
  .then((result) => {
    //working fine
  })
  .catch((result) => {
    //Something is not right.
  });

The only mandatory parameter is an instance of sequelize. Internally we will call the authenticate() function along with a valid sequelize config, so it should at least implement that function with a valid DB config.