systemhealth

2.0.1 • Public • Published

Systemhealth

Build Status Windows Tests Coveralls Coverage

Deps Status npm version npm downloads

Node module to run simple custom checks for your machine or it's connections.

NPM

Install

  npm install systemhealth

Initialize

var Systemhealth = require("systemhealth");
var health = new Systemhealth({}, ["foo", "bar"], require("./mychecks"));

Options

  • interval : ( Number optional: default = 60 ) Check interval in seconds
  • intervalVariance : ( Number optional: default = 0 ) If you are using the same configuration for multiple servers you can define a variance that will add random seconds to the interval until this value.
  • failCount : ( Number optional: default = 2 ) Count of failed checks per check until "die". E.g. Mark server as dead until 2 failed checks of the sql connection.
  • successCount : ( Number optional: default = 1 ) Count of successful checks until the server resurrect.
  • failTimeout : ( Number optional: default = 2000 ) Internal check timeout to wait for answers of check tasks

Methods

.start()

Start checking the health of the server and connections

Return

( Systemhealth ): The instance itself for chaining

.stop()

Stop checking interval

Return

( Systemhealth ): The instance itself for chaining

.die()

Mark the server as dead and stop the heartbeat. This is called until one check failed for option.failCount times.

Return

( Boolean ): Successful died. If the health is already dead it'll return false

.resurrect()

Resurrect the server and restart the heartbeat. This is called until all checks are successful for option.successCount times.

Return

( Boolean ): Successful died. If the health is already dead it'll return false

.getState()

return the last check state.

Return

( Object ): An object with the state of all checks.

Format: { "my-check-foo-name": [ {state}, {data} ] } {state}: Positive numbers represent the successful counts. Negative numbers represent the fail count.
{data}: Optional data or error infos

Events

started

Emitted on a successful start after the frist check.

stopped

Emitted on a check stop.

died

Emitted if the failCount has exceeded. So the server/machine is defined as dead.

resurrected

Emitted if the successCount has exceeded after the system was not dead. So the server/machine is defined as alive.

checked

Emitted after a check

Arguments

  • state : ( Object ) See method .getState() for teh description of the return

failed

A immediate event when a check fails.

Arguments

  • check : ( String ) The key of the failed check function
  • data : ( Any ) Optional data or error infos

Example

  var CHECKS = {
  	"memcached": function(){
  		var Memcached = require( 'memcached' );
  		var _client = new Memcached();
  		return function( cb ){
  			_client.version( function( err, version ){
  				if( err ){
  					cb( null, false, err ); // do not return a regular error. Just return false as second arg and optional info like the error object
  				}
  				cb( null, true, { _v: version } ); // just return true and optional information, that will be logged to redis metics
  			});
  		}
  	},
  	"sql": function(){
  		var _client = require( './my-sql-client42' );
  		return function( cb ){
  			_client.query( "SELECT 5", function( err, return ){
  				if( err ){
  					cb( null, false, err ); // do not return a regular error. Just return false as second arg and optional info like the error object
  				}
  				cb( null, true );
  			});
  		}
  	}
  }
  var Systemhealth = require( "systemhealth" );
  var health = new Systemhealth( { identifier: "my-server-name" }, [ "memcached", "sql" ], CHECKS );

Properties

alive

If the service is alive this property will be true

Return

( Boolean ): If it's alive

Testing

The tests are based on the mocha.js framework with should.js as assertaion lib. To start the test just call

	npm test

or

 grunt test

If you want to be more precice use the mocha cli

	mocha -R nyan -t 1337 test/main.js

Docker-Tests

If you want to test your module against multiple node versions you can use the docker tests.

Preparation

	# make sure you installed all dependencies
	npm install
	# build the files
	grunt build

Run

To run the tests through the defined versions run the following command:

	dockertests/run.sh

Release History

Version Date Description
2.0.0 2021-07-15 removed redis-heartbeat module. So the redis representation will no longer be available; updated docker tests to current node versions
1.0.0 2018-05-07 Updated deps., Updated redis-heartbeat without metrics to run on node 10 and coffee 2
0.1.1 2017-08-11 updated deps
0.1.0 2016-10-12 Optimized tests; Updated dependencies; Optimized Dev env.
0.0.5 2016-06-24 Added failed event to get immediate infos on an failed check;
0.0.4 2016-05-19 Updated dependencies; Updated dev env.; Removed generated code docs;
0.0.3 2016-01-07 Updated dependencies; Optimized Readme
0.0.2 2015-03-11 Small bugfix within redis connection listening
0.0.1 2014-11-20 Initial commit

NPM

Other projects

Name Description
redis-heartbeat Pulse a heartbeat to redis. This can be used to detach or attach servers to nginx or similar problems.
node-cache Simple and fast NodeJS internal caching. Node internal in memory cache like memcached.
rsmq A really simple message queue based on Redis
nsq-logger Nsq service to read messages from all topics listed within a list of nsqlookupd services.
nsq-topics Nsq helper to poll a nsqlookupd service for all it's topics and mirror it locally.
nsq-nodes Nsq helper to poll a nsqlookupd service for all it's nodes and mirror it locally.
nsq-watch Watch one or many topics for unprocessed messages.
redis-sessions An advanced session store for NodeJS and Redis
connect-redis-sessions A connect or express middleware to simply use the redis sessions. With redis sessions you can handle multiple sessions per user_id.
task-queue-worker A powerful tool for background processing of tasks that are run by making standard http requests.
soyer Soyer is small lib for serverside use of Google Closure Templates with node.js.
grunt-soy-compile Compile Goggle Closure Templates ( SOY ) templates inclding the handling of XLIFF language files.
backlunr A solution to bring Backbone Collections together with the browser fulltext search engine Lunr.js

The MIT License (MIT)

Copyright © 2021 Mathias Peter, http://www.tcs.de

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i systemhealth

Weekly Downloads

19

Version

2.0.1

License

MIT

Unpacked Size

28.8 kB

Total Files

6

Last publish

Collaborators

  • tcs-de