Home

Awesome

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

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

failed

A immediate event when a check fails.

Arguments

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

VersionDateDescription
2.0.02021-07-15removed redis-heartbeat module. So the redis representation will no longer be available; updated docker tests to current node versions
1.0.02018-05-07Updated deps., Updated redis-heartbeat without metrics to run on node 10 and coffee 2
0.1.12017-08-11updated deps
0.1.02016-10-12Optimized tests; Updated dependencies; Optimized Dev env.
0.0.52016-06-24Added failed event to get immediate infos on an failed check;
0.0.42016-05-19Updated dependencies; Updated dev env.; Removed generated code docs;
0.0.32016-01-07Updated dependencies; Optimized Readme
0.0.22015-03-11Small bugfix within redis connection listening
0.0.12014-11-20Initial commit

NPM

Other projects

NameDescription
redis-heartbeatPulse a heartbeat to redis. This can be used to detach or attach servers to nginx or similar problems.
node-cacheSimple and fast NodeJS internal caching. Node internal in memory cache like memcached.
rsmqA really simple message queue based on Redis
nsq-loggerNsq service to read messages from all topics listed within a list of nsqlookupd services.
nsq-topicsNsq helper to poll a nsqlookupd service for all it's topics and mirror it locally.
nsq-nodesNsq helper to poll a nsqlookupd service for all it's nodes and mirror it locally.
nsq-watchWatch one or many topics for unprocessed messages.
redis-sessionsAn advanced session store for NodeJS and Redis
connect-redis-sessionsA connect or express middleware to simply use the redis sessions. With redis sessions you can handle multiple sessions per user_id.
task-queue-workerA powerful tool for background processing of tasks that are run by making standard http requests.
soyerSoyer is small lib for serverside use of Google Closure Templates with node.js.
grunt-soy-compileCompile Goggle Closure Templates ( SOY ) templates inclding the handling of XLIFF language files.
backlunrA 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.