Health check utility for node
MIT License
Health check utility library
npm install --save healthkit
Checks for signal file and if it exists responds with 404
code
(to signal to load balancer to drain incoming requests),
if signal file doesn't exist, checks for upstream endpoint,
and returns 200
if endpoint is reachable and responds with successful http response.
Otherwise returns 500
code when all previous checks fail.
var healthkit = require('healthkit');
var myAppChecks = [
// first check for lets-drain signal file
{
status: 404, // respond with 404 if file present
file: '/etc/consul/test_file.exists'
},
// second check for underlying endpoint
// proceeded here if previous check failed
{
status: 200, // respond with 200 if endpoint responds with successful code (200-299)
http: 'http://simple.url/endpoint'
},
// third (empty, default) check
// proceeded here if previous check failed
{
status: 500 // everything failed, fail the health check
}
];
// Express handler
app.get('/health', function(req, res)
{
healthkit(myAppChecks, function(code, result)
{
res.status(code).send(result);
});
});
More examples can be found in test folder.
Or open an issue with questions and/or suggestions.
HealthKit is released under the MIT license.