1.1.1 • Published 5 years ago

pac-health-check v1.1.1

Weekly downloads
59
License
MIT
Repository
-
Last release
5 years ago

Check

pipeline status coverage report

Install

$ npm install pac-health-check

Usage

Health Check by Cron Job

var healthCheck = require('pac-health-check');

/* 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 job
var job = healthCheck.initJob(configuration)

// Wait 5000ms to let the job run
setTimeout(function () {
    var result = healthCheck.reportJob();
    console.log(JSON.stringify(result));
    //Stop the job
    job.stop();
}, 5000)

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 = require('pac-health-check');

//Sample configuration
var 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.reportOnDemand(configuration)
    .then(function (result) {
        console.log(JSON.stringify(result));
    })
    .catch(function (error) {
        console.log(error);
    });

Health Check Offline

var healthCheck = require('pac-health-check');
healthCheck.offline();

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 to ttl)

Specification

Common Configuration Object

RCOMultitudePropertyTypeDescription
C0-1cronStringFor health check by cron job flavor. Cron expression to run health check job(will run on init).
C0-1ttlNumberFor healch check on demand flavor. The time to live as number in seconds for local health check report cache. 0 = unlimited
O0-1max_retryNumberMax retry to determine the application status is DOWN (critical dependency is DOWN). Default is 3.
R1servicesObjectservices config for running actaul health check.
R1-N{service}Array of ObjectHealth Check for Supported Services
C0-1noncriticalBooleanIf this service is critical. Optional, default is undefined/false.

Supported Services:

  • api: Api Service
  • mssql: Microsoft SQL Server Service
  • cas: Cassandra Service
  • zkp: Zookeeper Service
  • kaf: kafka Service

Common Application Report Object

PropertyTypeDescription
statusStringValue is UP, DOWN, DEGRADED. Check Overall Status section for detail.
max_retryNumberFrom max_retry property in configuration, Default is 3.
servicesObjectHealth check report in detail for each service in configuration.
{service}index.statusStringValue is UP, DOWN. Check each service section of detail.
{service}index.noncriticalBooleanFrom configuration services.{service}[index].noncritical property

Overall Status

  • status is UP, When services.{service}[index].status is UP in all services.

  • status is DOWN, When any non noncritical servise services.{service}[index].status is DOWN.

  • status is DEGRADED, only if any noncritical servise services.{service}[index].status is DOWN.

Service api

Configuration

RCOMultitudePropertyTypeDescription
R1nameStringName of the API
R1urlStringUrl for health check
R1methodStringHttp method, only support GET for now.
O1services.apiindex.expectedStatusCodeNumber/StringOptional, accpet: Number(e.g.200); RegEx String(e.g."202|204"). Default value is "^[1-3][0-9]{2}$".

Report

PropertyTypeDescription
services.apiindex.nameStringFrom configuration
services.apiindex.urlStringFrom configuration
services.apiindex. methodStringFrom configuration
services.apiindex.statusStringCheck Api Status
services.apiindex.expectedStatusCodeStringFrom configuration.
services.apiindex.currentStatusCodeNumberActaul http status from response.

Api Status

  • report.api[index].status is UP by default.

  • report.api[index].status is DOWN, when health check result actualStatusCode is not matching expectedStatusCode.

Service mssql

Configuration

RCOMultitudePropertyTypeDescription
R1serverStringMssql Server hostname or IP
R1portNumberMssql Server port
R1databaseStringMssql database
C1userStringMssql username
C1passwordStringMssql password
O1connectionTimeoutNumberOptional, in miliseconds, default is 15000

Report

PropertyTypeDescription
services.mssqlindex.serverStringFrom configuration
services.mssqlindex.databaseStringFrom configuration
services.mssqlindex.statusStringValue is UP by default, DOWN when cannot connect to MsSql.

Service cas

Configuration

RCOMultitudePropertyTypeDescription
R1seedsStringCassandra seeds
R1keyspaceNumberCassandra keyspace
C1usernameStringusername
C1passwordStringpassword

Report

PropertyTypeDescription
services.casindex.seedsStringFrom configuration
services.casindex.keyspaceStringFrom configuration
services.casindex.statusStringValue is UP by default, DOWN when cannot connect to Cassandra.

Service zkp

Configuration

RCOMultitudePropertyTypeDescription
R1connectionStringStringZookeeper connection string. E.g. <host>:<port>/<root>

Report

PropertyTypeDescription
services.zkpindex.connectionStringStringFrom configuration
services.zkpindex.statusStringValue is UP by default, DOWN when cannot connect to Zookeeper.

Service kaf

Configuration

RCOMultitudePropertyTypeDescription
R1connectionStringStringKafka connection string. E.g. <host>:<port>/<root>/<kafka root>

Report

PropertyTypeDescription
services.kafindex.connectionStringStringFrom configuration
services.kafindex.statusStringValue is UP by default, DOWN when cannot connect to Kafka.

Sample Report

Heath Check

{
	"status": "UP",
	"max_retry": 3,
	"api": [{
		"name": "localhost 304",
		"url": "http://localhost:9999/304",
		"method": "GET",
		"expectedStatusCode": "200|202|304",
		"currentStatusCode": 304,
		"noncritical": true,
		"status": "UP"
	}, {
		"name": "localhost 200",
		"url": "http://localhost:9999/200",
		"method": "GET",
		"expectedStatusCode": 200,
		"currentStatusCode": 200,
		"status": "UP"
	}],
	"mssql": [{
		"server": "10.1.1.1",
		"database": "Access",
		"status": "UP"
	}],
	"cas": [{
		"seeds": "10.1.1.2",
		"keyspace": "dev_def",
		"status": "UP"
	}],
	"zkp": [{
		"connectionString": "10.1.1.3:2181/dev",
		"status": "UP"
	}],
	"kaf": [{
		"connectionString": "10.1.1.4:2181/dev/kafka",
		"status": "UP"
	}]
}

Heath Check Offline

{
    "status": "DOWN",
    "max_retry": 2,
    "api": [{
        "name": "localhost 202",
        "url": "http://localhost:9999/202",
        "method": "GET",
        "expectedStatusCode": 202,
        "currentStatusCode": 202,
        "status": "UP"
    }, {
        "name": "localhost 202 2",
        "url": "http://localhost:9999/202",
        "method": "GET",
        "expectedStatusCode": 202,
        "currentStatusCode": 202,
        "status": "UP"
    }],
    "mssql": [{
        "server": "10.231.22.213",
        "database": "Access",
        "status": "UP"
    }, {
        "server": "10.231.22.212",
        "database": "Access",
        "status": "UP"
    }],
    "cas": [{
        "seeds": "10.231.23.40",
        "keyspace": "dev_def",
        "status": "UP"
    }, {
        "seeds": "10.231.23.41",
        "keyspace": "dev_def",
        "status": "UP"
    }],
    "zkp": [{
        "connectionString": "dev-usw-r1-def-h1:2181/dev",
        "status": "UP"
    }, {
        "connectionString": "dev-usw-r2-def-h2:2181/dev",
        "status": "UP"
    }],
    "kaf": [{
        "connectionString": "dev-usw-r1-def-h1:2181/dev/kafka",
        "status": "UP"
    }, {
        "connectionString": "dev-usw-r2-def-h2:2181/dev/kafka",
        "status": "UP"
    }],
    "offline": true
}

Test

Test Coverage

File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files10097.41100100
src10095100100
consts.js100100100100
healthcheck.js10094.4410010066,96,99
src/component100100100100
api.js100100100100
cas.js100100100100
kaf.js100100100100
mssql.js100100100100
zkp.js100100100100
1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago