README
A simple Javascript round robin health checker
Install
npm install @aftonbladet/health-check --save
Usage
Simple initialization
import { initHealthCheck, isHealthy } from '@aftonbladet/health-check';
initHealthCheck({ healthCheckUrls: ['http://www.aftonbladet.se/'] });
if (isHealthy()) {
// System is UP
} else {
// System is DOWN!
}
This will initialize a health checker that checks http://www.aftonbladet.se
every three seconds.
If any of five consecutive checks returns a status in the 200 to 299 range, the check is considered
to be healthy.
Advanced initialization
import { initHealthCheck, isHealthy } from '@aftonbladet/health-check';
initHealthCheck({
healthCheckUrls: ['http://www.aftonbladet.se/', 'https://www.aftonbladet.se/sportbladet'],
healthCheckInterval, 1000,
numberOfChecks: 3,
});
if (isHealthy()) {
// System is UP
} else {
// System is DOWN!
}
This will instead initialize a health checker that round robins through the URLs in healthCheckUrls
every second.
If any of three consecutive checks returns a status in the 200 to 299 range, the check is considered
to be healthy.
The following parameters are accepted by initHealthCheck
:
- healthCheckUrls a list of URLs to check
- [healthCheckInterval=3000] the time in ms to wait in between each URL to check
- [readTimeout=1000] the read timeout in ms used when checking the URLs
- [numberOfChecks=5] the size of the CHECKS array
- [logger=NOOP] a https://github.schibsted.io/ab/logger instance if you want logging
Publish
npm version major|minor|patch