Check
Install
$ npm install pac-health-check
Usage
Health Check by Cron Job
var healthCheck = ; /* Sample configuration */ const configuration = cron: '* */5 * * * *' max_retry: 2 services: api: name: 'localhost 304' url: 'http://localhost:' + port + '/304' method: 'GET' expectedStatusCode: "200|202|304" name: 'localhost 200' url: 'http://localhost:' + port + '/200' method: 'GET' expectedStatusCode: 200 mssql: user: "username" password: "password" server: "server" port: 123 database: "database" connectionTimeout: 2000 cas: seeds: "seed ip" keyspace: "key space" username: "username" password: "password" zkp: connectionString: "<host>:<port>/<root>" kaf: connectionString: "<host>:<port>/<root>/<kafka root>" ; //Init jobvar job = healthCheck // Wait 5000ms to let the job run
Healch Check on Demand
healthCheck.reportOnDemand(configuration)
It is recommended to set a ttl configuration.ttl
(in seconds).
If ttl
is set, healthCheck will leverage local cache.
var healthCheck = ; //Sample configurationvar configuration = ttl: 600 services: api: name: 'httpstat.us 202' url: 'http://httpstat.us/202' method: 'GET' expectedStatusCode: "200|204" noncritical: true name: 'httpstat.us 200' url: 'https://httpstat.us/200' method: 'GET' expectedStatusCode: 200 ; healthCheck ;
Health Check Offline
var healthCheck = ;healthCheck;
Once offline
method is called:
- Both cron job and on demand request will stop perform actual health check. And health check cannont be resumed.
- Health check status is
DOWN
, previous report is still accessible. (on demand request caching subjects tottl
)
Specification
Common Configuration Object
RCO | Multitude | Property | Type | Description |
---|---|---|---|---|
C | 0-1 | cron | String | For health check by cron job flavor. Cron expression to run health check job(will run on init). |
C | 0-1 | ttl | Number | For healch check on demand flavor. The time to live as number in seconds for local health check report cache. 0 = unlimited |
O | 0-1 | max_retry | Number | Max retry to determine the application status is DOWN (critical dependency is DOWN ). Default is 3. |
R | 1 | services | Object | services config for running actaul health check. |
R | 1-N | →{service} | Array of Object | Health Check for Supported Services |
C | 0-1 | →→noncritical | Boolean | If this service is critical. Optional, default is undefined/false. |
Supported Services:
api
: Api Servicemssql
: Microsoft SQL Server Servicecas
: Cassandra Servicezkp
: Zookeeper Servicekaf
: kafka Service
Common Application Report Object
Property | Type | Description |
---|---|---|
status | String | Value is UP , DOWN , DEGRADED . Check Overall Status section for detail. |
max_retry | Number | From max_retry property in configuration, Default is 3. |
services | Object | Health check report in detail for each service in configuration. |
→ {service}[index].status | String | Value is UP , DOWN . Check each service section of detail. |
→ {service}[index].noncritical | Boolean | From configuration services.{service}[index].noncritical property |
Overall Status
-
status
isUP
, Whenservices.{service}[index].status
isUP
in all services. -
status
isDOWN
, When any nonnoncritical
serviseservices.{service}[index].status
isDOWN
. -
status
isDEGRADED
, only if anynoncritical
serviseservices.{service}[index].status
isDOWN
.
api
Service Configuration
RCO | Multitude | Property | Type | Description |
---|---|---|---|---|
R | 1 | name | String | Name of the API |
R | 1 | url | String | Url for health check |
R | 1 | method | String | Http method, only support GET for now. |
O | 1 | services.api[index].expectedStatusCode | Number/String | Optional, accpet: Number(e.g.200 ); RegEx String(e.g."202|204" ). Default value is "^[1-3][0-9]{2}$" . |
Report
Property | Type | Description |
---|---|---|
services.api[index].name | String | From configuration |
services.api[index].url | String | From configuration |
services.api[index]. method | String | From configuration |
services.api[index].status | String | Check Api Status |
services.api[index].expectedStatusCode | String | From configuration. |
services.api[index].currentStatusCode | Number | Actaul http status from response. |
Api Status
-
report.api[index].status
isUP
by default. -
report.api[index].status
isDOWN
, when health check resultactualStatusCode
is not matchingexpectedStatusCode
.
mssql
Service Configuration
RCO | Multitude | Property | Type | Description |
---|---|---|---|---|
R | 1 | server | String | Mssql Server hostname or IP |
R | 1 | port | Number | Mssql Server port |
R | 1 | database | String | Mssql database |
C | 1 | user | String | Mssql username |
C | 1 | password | String | Mssql password |
O | 1 | connectionTimeout | Number | Optional, in miliseconds, default is 15000 |
Report
Property | Type | Description |
---|---|---|
services.mssql[index].server | String | From configuration |
services.mssql[index].database | String | From configuration |
services.mssql[index].status | String | Value is UP by default, DOWN when cannot connect to MsSql. |
cas
Service Configuration
RCO | Multitude | Property | Type | Description |
---|---|---|---|---|
R | 1 | seeds | String | Cassandra seeds |
R | 1 | keyspace | Number | Cassandra keyspace |
C | 1 | username | String | username |
C | 1 | password | String | password |
Report
Property | Type | Description |
---|---|---|
services.cas[index].seeds | String | From configuration |
services.cas[index].keyspace | String | From configuration |
services.cas[index].status | String | Value is UP by default, DOWN when cannot connect to Cassandra. |
zkp
Service Configuration
RCO | Multitude | Property | Type | Description |
---|---|---|---|---|
R | 1 | connectionString | String | Zookeeper connection string. E.g. <host>:<port>/<root> |
Report
Property | Type | Description |
---|---|---|
services.zkp[index].connectionString | String | From configuration |
services.zkp[index].status | String | Value is UP by default, DOWN when cannot connect to Zookeeper. |
kaf
Service Configuration
RCO | Multitude | Property | Type | Description |
---|---|---|---|---|
R | 1 | connectionString | String | Kafka connection string. E.g. <host>:<port>/<root>/<kafka root> |
Report
Property | Type | Description |
---|---|---|
services.kaf[index].connectionString | String | From configuration |
services.kaf[index].status | String | Value is UP by default, DOWN when cannot connect to Kafka. |
Sample Report
Heath Check
Heath Check Offline
Test
Test Coverage
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---|---|---|---|---|---|
All files | 100 | 97.41 | 100 | 100 | |
src | 100 | 95 | 100 | 100 | |
→ consts.js | 100 | 100 | 100 | 100 | |
→ healthcheck.js | 100 | 94.44 | 100 | 100 | 66,96,99 |
src/component | 100 | 100 | 100 | 100 | |
→ api.js | 100 | 100 | 100 | 100 | |
→ cas.js | 100 | 100 | 100 | 100 | |
→ kaf.js | 100 | 100 | 100 | 100 | |
→ mssql.js | 100 | 100 | 100 | 100 | |
→ zkp.js | 100 | 100 | 100 | 100 |