Skip to content

Commit

Permalink
Add health status functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
draco2003 committed Mar 28, 2013
1 parent 045b1de commit 8dadf9f
Show file tree
Hide file tree
Showing 3 changed files with 20 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 @@ -44,4 +45,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
15 changes: 14 additions & 1 deletion stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ config.configFile(process.argv[2], function (config, oldConfig) {
});

mgmtServer = net.createServer(function(stream) {
var healthStatus = config.healthStatus || 'up';
stream.setEncoding('ascii');

stream.on('error', function(err) {
Expand All @@ -246,7 +247,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

0 comments on commit 8dadf9f

Please sign in to comment.