Merge pull request #311 from etsy/process_mgmt

Allow for setting the process title
This commit is contained in:
Dan Rowe 2013-08-02 11:39:30 -07:00
Родитель ce6ec0911c dd1ad7b238
Коммит b4c9adfc08
4 изменённых файлов: 87 добавлений и 10 удалений

Просмотреть файл

@ -25,6 +25,11 @@ 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
NOTE: This does not work on Mac's with node versions prior to v0.10
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

27
lib/process_mgmt.js Normal file
Просмотреть файл

@ -0,0 +1,27 @@
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) {
process.title = config.title;
}
} else {
process.title = 'statsd';
}
}

Просмотреть файл

@ -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');
@ -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
@ -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();
});

Просмотреть файл

@ -0,0 +1,51 @@
var process_mgmt = require('../lib/process_mgmt')
, os = require('os');
var config = {}
, can_set_title = true;
module.exports = {
setUp: function(callback) {
config = {};
version_number = process.version.split(".")[1];
platform = os.platform();
can_set_title = (version_number >= 10 || platform != 'darwin');
callback();
},
test_setting_title: function(test){
if (can_set_title) {
test.expect(1);
process_title = process.title;
config.title = "test-statsd";
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");
} else {
console.log("Not running this test, due to this being a node version before v0.10 and a Darwin os");
}
test.done();
},
test_no_title: function(test){
test.expect(1);
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){
if (can_set_title) {
test.expect(1);
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");
} else {
console.log("Not running this test, due to this being a node version before v0.10 and a Darwin os");
}
test.done();
}
};