Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add health status functionality #280

Merged
merged 3 commits into from

2 participants

@draco2003

Adds health check functionality to Statsd. This allows the ability to check the current status, as well as the ability to change the state manually in preparation for cluster mode functionality.

stats.js
@@ -402,3 +415,13 @@ config.configFile(process.argv[2], function (config, oldConfig) {
}
}
});
+
+process.on('SIGTERM', function() {
+ if (config.debug) {
+ l.log('Going Down in ' + flushInterval + 'ms');
+ }
+ healthStatus = 'down';
+ setTimeout(function() {
+ process.exit();
+ }, flushInterval);
@mrtazz Owner
mrtazz added a note

Maybe we just want to flush directly here and then just wait 1 or 2 seconds and call process.exit() afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mrtazz
Owner

otherwise lgtm

@mrtazz
Owner

:shipit:

@draco2003 draco2003 merged commit 3b1bbac into master

1 check passed

Details default The Travis build passed
@draco2003 draco2003 deleted the health_status branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. @draco2003
  2. @draco2003

    adding SIGTERM handling

    draco2003 authored
Commits on Apr 8, 2013
  1. @draco2003

    Cleanup shutdown process

    draco2003 authored
This page is out of date. Refresh to see the latest.
Showing with 32 additions and 1 deletion.
  1. +5 −0 docs/admin_interface.md
  2. +1 −0  exampleConfig.js
  3. +26 −1 stats.js
View
5 docs/admin_interface.md
@@ -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:
@@ -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.
View
1  exampleConfig.js
@@ -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)
View
27 stats.js
@@ -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) {
@@ -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":
@@ -402,3 +415,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();
+});
Something went wrong with that request. Please try again.