diff --git a/lib/configuration.js b/lib/configuration.js index 5d82f914db91f8b44aa7fc2cc4a543cec2de0a1d..d0bc838e0498c8143cf585fa614e5fd452b04420 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -127,7 +127,7 @@ var conf = module.exports = convict({ statsd: { enabled: { doc: "enable UDP based statsd reporting", - format: 'boolean = true', + format: 'boolean = false', env: 'ENABLE_STATSD' }, host: "string?", diff --git a/lib/statsd.js b/lib/statsd.js index f7278dca5628b18f7f7329cb04043078822ef653..20cc7dfdca7151c6390d321af6be812b1f29aeec 100644 --- a/lib/statsd.js +++ b/lib/statsd.js @@ -3,8 +3,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ const -StatsD = require("node-statsd").StatsD, -config = require('./configuration'); +config = require('./configuration'), +logger = require('./logging').logger; + +var StatsD = false; +try { + StatsD = require("node-statsd").StatsD; +} catch (requireError) { + // its ok, its an optionalDependency +} const PREFIX = "browserid." + config.get('process_type') + "."; @@ -23,11 +30,15 @@ module.exports = { var statsd_config = config.get('statsd'); if (statsd_config && statsd_config.enabled) { - var options = {}; - options["host"] = options["host"] || "localhost"; - options["port"] = options["port"] || 8125; - - statsd = new StatsD(options["host"], options["port"]); + if (StatsD) { + var options = {}; + options["host"] = options["host"] || "localhost"; + options["port"] = options["port"] || 8125; + + statsd = new StatsD(options["host"], options["port"]); + } else { + logger.error('statsd config enabled, but node-statsd not installed.'); + } } process.on('uncaughtException', function(err) { diff --git a/package.json b/package.json index 1e45de6881495042a873d00681c892f3c587fa08..40c6f74328e97874f5c0723953c0fc249655e3d5 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "mustache": "0.3.1-dev", "jwcrypto": "0.3.2", "mysql": "0.9.5", - "node-statsd": "https://github.com/downloads/lloyd/node-statsd/0509f85.tgz", "nodemailer": "0.1.24", "mkdirp": "0.3.0", "optimist": "0.2.8", @@ -34,6 +33,9 @@ "validator": "0.4.9", "winston": "0.6.2" }, + "optionalDependencies": { + "node-statsd": "https://github.com/downloads/lloyd/node-statsd/0509f85.tgz" + }, "devDependencies": { "vows": "0.5.13", "awsbox": "0.2.12", @@ -46,6 +48,6 @@ "start": "./scripts/run_locally.js" }, "engines": { - "node": ">= 0.6.2" + "node": ">= 0.6.7" } }