Skip to content

Commit

Permalink
Allow for setting the process wtitle, or opting to let the os do it l…
Browse files Browse the repository at this point in the history
…ike previous versions
  • Loading branch information
draco2003 committed Jul 2, 2013
1 parent 9b949e5 commit 4541e11
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
3 changes: 3 additions & 0 deletions exampleConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ 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]
title : Allows for overriding the process title. [default: statsd]
if set to false, will not override the process title and let the OS set it.
The length of the title has to be less than or equal to the binary name + cli arguments
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
Expand Down
34 changes: 34 additions & 0 deletions lib/process_mgmt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var util = require('util');

var conf;

exports.init = function(config) {
conf = config;
exports.set_title(config);

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

}

exports.set_title = function(config) {
if (config.title !== undefined) {
if (config.title) {
if (process.title.length >= config.title.length) {
process.title = config.title;
} else {
// check that conf is defined so we don't error in tests
if (conf !== undefined && conf.debug) {
util.log("config.title is to long, needs to be less than or equal to" + process.title.length);
}
}
}
} else {
process.title = 'statsd';
}
}
14 changes: 4 additions & 10 deletions stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var dgram = require('dgram')
, logger = require('./lib/logger')
, set = require('./lib/set')
, pm = require('./lib/process_metrics')
, process_mgmt = require('./lib/process_mgmt')
, mgmt = require('./lib/mgmt_console');


Expand Down Expand Up @@ -137,6 +138,9 @@ var l;

config.configFile(process.argv[2], function (config, oldConfig) {
conf = config;

process_mgmt.init(config);

l = new logger.Logger(config.log || {});

// setup config for stats prefix
Expand Down Expand Up @@ -410,16 +414,6 @@ config.configFile(process.argv[2], function (config, oldConfig) {
}
});

process.title = 'statsd';

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

process.on('exit', function () {
flushMetrics();
});
44 changes: 44 additions & 0 deletions test/process_mgmt_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var process_mgmt = require('../lib/process_mgmt');

var config = {}
module.exports = {

setUp: function(callback) {
config = {};
callback();
},

test_valid_title: function(test){
test.expect(1);
process_title = process.title;
config.title = process_title.substring(1);
process_mgmt.set_title(config);
test.ok(process.title == config.title, "Can set a title that is less than or equal to the process title length");
test.done();
},

test_invalid_title: function(test){
process_title = process.title;
test_title = process.title + "1";
config.title = test_title;
process_mgmt.set_title(config);
test.ok(process.title == process_title, "Can't set a title that is longer than the process.title length");
test.done();
},

test_no_title: function(test){
process_title = process.title;
config.title = false;
process_mgmt.set_title(config);
test.ok(process_title == process.title, "A config.title of false should not override the default node process.title");
test.done();
},

test_default_title: function(test){
default_title = 'statsd';
process_mgmt.set_title(config);
test.ok(process.title == default_title, "If no config.title option set, set the process.title to statsd");
test.done();
}

};

0 comments on commit 4541e11

Please sign in to comment.