Skip to content

Commit

Permalink
Merge pull request statsd#280 from etsy/health_status
Browse files Browse the repository at this point in the history
Add health status functionality, and handle SIGTERM more gracefully.
  • Loading branch information
draco2003 committed Apr 8, 2013
2 parents d1cb58e + 4cd8167 commit 3b1bbac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/admin_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ available:
* counters - a dump of all the current counters
* gauges - a dump of all the current gauges
* timers - a dump of the current timers
* health - a way to set the health status of statsd

The stats output currently will give you:

Expand Down Expand Up @@ -42,4 +43,8 @@ A simple nagios check can be found in the utils/ directory that can be used to
check metric thresholds, for example the number of seconds since the last
successful flush to graphite.

The health output:
* the health command alone allows you to see the current health status.
* using health up or health down, you can change the current health status.
* the healthStatus configuration option allows you to set the default health status at start.

1 change: 1 addition & 0 deletions exampleConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Optional Variables:
mgmt_address: address to run the management TCP interface on
[default: 0.0.0.0]
mgmt_port: port to run the management TCP interface on [default: 8126]
healthStatus: default health status to be returned and statsd process starts ['up' or 'down', default: 'up']
dumpMessages: log all incoming messages
flushInterval: interval (in ms) to flush to Graphite
percentThreshold: for time information, calculate the Nth percentile(s)
Expand Down
27 changes: 26 additions & 1 deletion stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var pctThreshold = null;
var flushInterval, keyFlushInt, server, mgmtServer;
var startup_time = Math.round(new Date().getTime() / 1000);
var backendEvents = new events.EventEmitter();
var healthStatus = config.healthStatus || 'up';

// Load and init the backend from the backends/ directory.
function loadBackend(config, name) {
Expand Down Expand Up @@ -249,7 +250,19 @@ config.configFile(process.argv[2], function (config, oldConfig) {

switch(cmd) {
case "help":
stream.write("Commands: stats, counters, timers, gauges, delcounters, deltimers, delgauges, quit\n\n");
stream.write("Commands: stats, counters, timers, gauges, delcounters, deltimers, delgauges, health, quit\n\n");
break;

case "health":
if (cmdline.length > 0) {
var cmdaction = cmdline[0].toLowerCase();
if (cmdaction === 'up') {
healthStatus = 'up';
} else if (cmdaction === 'down') {
healthStatus = 'down';
}
}
stream.write("health: " + healthStatus + "\n");
break;

case "stats":
Expand Down Expand Up @@ -405,3 +418,15 @@ config.configFile(process.argv[2], function (config, oldConfig) {
}
}
});

process.on('SIGTERM', function() {
if (conf.debug) {
util.log('Starting Final Flush');
}
healthStatus = 'down';
process.exit();
});

process.on('exit', function () {
flushMetrics();
});

0 comments on commit 3b1bbac

Please sign in to comment.