@lcdev/health-check
v0.1.9
Published
Health check endpoint for APIs
Downloads
3
Keywords
Readme
Launchcode Health Check
Common health check route for services. This is a thin wrapper over maikai. We use it for kubernetes health checking.
yarn add @lcdev/health-check@VERSION
This module assumes that you're using a koa server.
Use it simply by using the middleware. Be careful to not guard it under authentication.
import { createHealthEndpoint, createSystemHealthEndpoint } from '@lcdev/health-check';
// kubernetes compliant health check on /health
app.use(createHealthEndpoint());
// more specific health checking on /system-health
// you might want this to be locked down by authentication to avoid leaking system details
app.use(createSystemHealthEndpoint());
The createHealthEndpoint
middleware accepts (path: string)
, (checks: Check[])
or (path: string, checks: Check[])
.
You probably want to include other aspects of your system for a health check. For example,
here's checking a database and redis connection.
// assuming 'knex' and 'redis' are variables
app.use(
createHealthEndpoint([
{
component: 'postgres',
metric: 'alive',
async check() {
return knex
.raw('select 1')
.then(() => ({ status: 'pass' }))
.catch(() => ({ status: 'fail' }));
},
},
{
component: 'redis',
metric: 'alive',
async check() {
return redis
.echo('ping')
.then(() => ({ status: 'pass' }))
.catch(() => ({ status: 'fail' }));
},
},
]),
);