From 1e8f0d0089e6f75fa8052f7011e677d05484996a Mon Sep 17 00:00:00 2001 From: Bryan Larsen Date: Thu, 15 Sep 2016 11:50:34 -0400 Subject: [PATCH] Add debug option that can be used to turn off whitelist log messages. If you use the whitelist option, it generates a log line everytime the whitelist excludes a metric. This can generate thousands of log messages every 10 seconds, flooding your journal. Add the configuration variable 'debug', which when explicitly set to false, turns off these messages. --- README.md | 3 ++- lib/aws-cloudwatch-statsd-backend.js | 34 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c3cef39..2def853 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,8 @@ Using cloudwatch will incur a cost for each metric sent. In order to control you accessKeyId: 'YOUR_ACCESS_KEY_ID', secretAccessKey: 'YOUR_SECRET_ACCESS_KEY', region: 'YOUR_REGION', - whitelist: ['YOUR_FULL_METRIC_NAME'] + whitelist: ['YOUR_FULL_METRIC_NAME'], + debug: false } } diff --git a/lib/aws-cloudwatch-statsd-backend.js b/lib/aws-cloudwatch-statsd-backend.js index 1fff377..ccb8339 100644 --- a/lib/aws-cloudwatch-statsd-backend.js +++ b/lib/aws-cloudwatch-statsd-backend.js @@ -60,11 +60,11 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) { if (key.indexOf('statsd.') == 0) continue; - if(this.config.whitelist && this.config.whitelist.length >0 && this.config.whitelist.indexOf(key) == -1) { - console.log("Key (counter) "+key+" not in whitelist"); - continue; - } - + if(this.config.whitelist && this.config.whitelist.length >0 && this.config.whitelist.indexOf(key) == -1) { + if (this.config.debug !== false) console.log("Key (counter) "+key+" not in whitelist"); + continue; + } + var names = this.config.processKeyForNamespace ? this.processKey(key) : {}; var namespace = this.config.namespace || names.namespace || "AwsCloudWatchStatsdBackend"; var metricName = this.config.metricName || names.metricName || key; @@ -87,10 +87,10 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) { for (key in timers) { if (timers[key].length > 0) { - if(this.config.whitelist && this.config.whitelist.length >0 && this.config.whitelist.indexOf(key) == -1) { - console.log("Key (counter) "+key+" not in whitelist"); - continue; - } + if(this.config.whitelist && this.config.whitelist.length >0 && this.config.whitelist.indexOf(key) == -1) { + if (this.config.debug !== false) console.log("Key (counter) "+key+" not in whitelist"); + continue; + } var values = timers[key].sort(function (a,b) { return a-b; }); var count = values.length; @@ -140,10 +140,10 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) { for (key in gauges) { - if(this.config.whitelist && this.config.whitelist.length >0 && this.config.whitelist.indexOf(key) == -1) { - console.log("Key (counter) "+key+" not in whitelist"); - continue; - } + if(this.config.whitelist && this.config.whitelist.length >0 && this.config.whitelist.indexOf(key) == -1) { + if (this.config.debug !== false) console.log("Key (counter) "+key+" not in whitelist"); + continue; + } var names = this.config.processKeyForNamespace ? this.processKey(key) : {}; var namespace = this.config.namespace || names.namespace || "AwsCloudWatchStatsdBackend"; @@ -167,10 +167,10 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) { for (key in sets) { - if(this.config.whitelist && this.config.whitelist.length >0 && this.config.whitelist.indexOf(key) == -1) { - console.log("Key (counter) "+key+" not in whitelist"); - continue; - } + if(this.config.whitelist && this.config.whitelist.length >0 && this.config.whitelist.indexOf(key) == -1) { + if (this.config.debug !== false) console.log("Key (counter) "+key+" not in whitelist"); + continue; + } var names = this.config.processKeyForNamespace ? this.processKey(key) : {}; var namespace = this.config.namespace || names.namespace || "AwsCloudWatchStatsdBackend";