autohost-canary
Adds an end-point for tracking in-depth status of a service. Services determine what gets reported as status via API.
Installation & Setup
npm install autohost-canary -S
var autohost = require( "autohost" );
var host;
var hyped = require( "hyped" )();
var fount = require( "fount" );
var postal = require( "postal" );
var channel = postal.channel( "ahcanary" );
fount.register( "ahcanary", channel );
host = hyped.createHost( autohost, {
port: config.nonstop.host.port,
modules: [
"autohost-canary"
],
fount: fount
}, function() {
host.start();
} );
rabbit.on( "connected", function( msg ) {
channel.publish( "rabbit", { value: "connected" } );
} );
rabbit.on( "closed", function( msg ) {
channel.publish( "rabbit", { value: "closed" } );
} );
rabbit.on( "failed", function( msg ) {
channel.publish( "rabbit", { value: "connection failed" } );
} );
HTTP API
The only thing you can do is get the status:
GET /api/ah/status
If you're using hyped
then you can access the same endpoint via status:self
. The names and routes were chosen to make the chance of collision extremely low.
The result will be a JSON object with your keys/values and a few bonus items:
{
"memory": { a hash containing memory usage details },
"uptime": "a human readable duration",
"version": "a version specifier from your package.json OR nonstop-info"
}
Status Messages
You get a little more control on what status is reported based on how you format your message.
Default
You can publish a message with default
to tell canary that if the key is removed or reset to still display the key with the default value.
channel.publish( "database", { default: "pending" } );
Reset
Publishing this message will cause the key to revert to undefined or a previously provided default value.
channel.publish( "key", { reset: true } );
Value
Updates the current status for the topic to the value provided.
channel.publish( "usersConnected", x );
Time to live (milliseconds)
Some values are only good for a period of time or don't have a compensating event to tell you when the value has changed. To address this, you can put a ttl
property on the message body which will cause the value to be removed from status or revert to a previously assigned default.
channel.publish( "processingMessages", value: true, ttl: 100 )