Skip to content

Simple module to check the health status of a service dependencies

License

Notifications You must be signed in to change notification settings

martini97/services-healthcheck

Repository files navigation

services-healthcheck

Build Status
Simple module to check the health status of a service dependencies

Installing

To install it, just use npm:
npm i services-healthcheck

Usage

Parameters

  • services:
    An object mapping the service name to its URL or to it's URL getter (the service must have a /_ping route), or to a knex connection. Supported DB's: Postgres, MSSQL, MySQL, MariaDB, SQLite3, and Oracle.
const express = require('express');
const knex = require('knex');
const healthcheck = require('services-healthcheck').default;

const getRandomArbitrary = (min, max) => {
  return Math.random() * (max - min) + min;
};

const getServiceUrl = () => return `http://service-{getRandomArbitrary(5, 10)}`;

const knexInstance = knex({
  client: 'mysql',
  connection: {
    host: 'localhost',
    user: 'user',
    password: 'password',
    database: 'database',
    port: 3306,
  },
  debug: false,
});

const services = {
  'service-1': 'http://service-1',
  'service-2': 'http://service-2',
  'service-3': 'http://service-3',
  'service-4': 'http://service-4',
  'service-5': { url: 'http://service-custom-ping', route: '/health/_ping' },
  'service-x': getServiceUrl,
  'db-1':      { knex: knexInstance },
  'queue-1':   { queue: { host: 'localhost', port: '5672' } }
};

function application() {
  const app = express();
  app.use(healthcheck(services));
  return app;
};

async function start() {
  const app = await application();
  app.listen(3000, () => console.log('http://localhost:3000'));
}

start();

After that, it will add a /_health route, that returns the status of the services passed

About

Simple module to check the health status of a service dependencies

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published