パッケージの詳細

health

cliffano3.1m0.3.0

Resource status monitoring library.

health, status, monitor

readme

Avatar

Build Status Dependencies Status Coverage Status Published Version
npm Badge

Health

Health is a resource status monitoring library.

This is handy when you want to monitor the status of multiple resources using a simple configuration file. For example, if your application requires a web service and a MongoDB database to be available, Health module can monitor those resources and return status ok/fail against each resource along with the response time.

It also supports result caching via ttl attribe of each resource, which is handy when you want to monitor multiple resources at a different interval or to reduce the load on certain resources.

Installation

npm install -g health 

Usage

// use default formatter
var health = new (require('health'))(
  setup: [ { name: 'google', uri: 'http://google.com' } ]
);

// use built-in formatter (html, text, or xml)
var health = new (require('health'))(
  setup: [ { name: 'google', uri: 'http://google.com' } ],
  formatter: 'html'
);

// use custom formatter function
var health = new (require('health'))(
  setup: [ { name: 'google', uri: 'http://google.com' } ],
  formatter: function (results) {
    return results.join('|');
  }
);

// check resources
health.check(function (err, result) {
});

From command-line:

health -f html -s health.json check

Configuration

Health setup is just a simple JSON:

[
  { "name": "Google", "uri", "http://google.com", "statusCodes": [ 200 ] },
  { "name": "GMail", "uri", "https://mail.google.com", "timeout": "1000" },
  { "name": "MongoDB", "uri": "mongodb://somehost:27017", "timeout": 200, "ttl": 30000 },
  { "name": "Temp", "uri": "file:///tmp", "mode": "777", "ttl": 360000 }
]
Attribute Type Description Protocol Usage Default Example
uri string Resource URI to check All Mandatory mongodb://somehost:27017
name string Resource name All Optional someapp
ttl number Cache time to live in milliseconds All Optional 30000
lenient boolean Replace fail or error with warning All Optional false true, false
group string Resource group name, status is set to warning when there's at least one group member having success/warning status, group members status is set to fail/error only when none of the group members has success/warning status All Optional databases, apps, datacenter1
timeout number Request/connect timeout in milliseconds http, https, mongodb Optional 500
statusCode array An array of acceptable response HTTP status codes http, https Optional [ 200, 409 ]
text array An array of all texts that must exist in response body, any of them does not exist means status FAIL http, https Optional [ 'foo', 'bar' ]
mode string 3-digit file/directory mode file Optional 777, 644

Colophon

Developer's Guide

Build reports:

更新履歴

0.3.0-pre

  • Set min node engine to >= v0.10.0

0.2.3

  • Fix info icon display on html report when there's no info
  • Improve mongo checker error message from mongodb dep

0.2.2

  • Add result timestamp (when check is started)
  • Rename http(s) attributes: statusCodes -> statusCode, texts -> text
  • All checker attributes handle <attribute> and <attribute>-or
  • Add health#clearCache
  • All checker attributes handle regular expression
  • Add threshold support to resource group

0.2.1

  • Add file checker

0.2.0

  • Add result model
  • Remove xml formatter

0.1.1

  • Add group check attribute
  • Add headers and body as http(s) debug info
  • Fix exit code when all checks are successful

0.1.0

  • Add error status to differentiate error from check failures
  • Add success, failure, and error messages to improve reporting
  • Rename responseTime to duration (check time in milliseconds)
  • Change status ok to success
  • Add lenient check attribute and warning status

0.0.5

  • Add cli formatter
  • Fix CLI exit code to be the number of non-ok status

0.0.4

  • Add CLI with init and check commands

0.0.3

  • Add html formatter

0.0.2

  • Change status from OK/FAIL to ok/fail

0.0.1

  • Initial version