Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions lib/aws-cloudwatch-statsd-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) {
var sets = metrics.sets;

// put all currently accumulated counter metrics into an array
var currentCounterMetrics = [];
var currentNamespaces = {};
var namespace = "AwsCloudWatchStatsdBackend";
for (key in counters) {
if (key.indexOf('statsd.') == 0)
Expand All @@ -126,19 +126,21 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) {
var names = this.config.processKeyForNamespace ? this.processKey(key) : {};
namespace = this.config.namespace || names.namespace || "AwsCloudWatchStatsdBackend";
var metricName = this.config.metricName || names.metricName || key;
if (!currentNamespaces.hasOwnProperty(namespace)) currentNamespaces[namespace] = []

currentCounterMetrics.push({
currentNamespaces[namespace].push({
MetricName: metricName,
Unit: 'Count',
Timestamp: new Date(timestamp * 1000).toISOString(),
Value: counters[key]
});
}

this.batchSend(currentCounterMetrics, namespace);
for (namespace in currentNamespaces){
this.batchSend(currentNamespaces[namespace], namespace);
}

// put all currently accumulated timer metrics into an array
var currentTimerMetrics = [];
currentNamespaces = {};
for (key in timers) {
if (timers[key].length > 0) {

Expand Down Expand Up @@ -172,8 +174,9 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) {
var names = this.config.processKeyForNamespace ? this.processKey(key) : {};
namespace = this.config.namespace || names.namespace || "AwsCloudWatchStatsdBackend";
var metricName = this.config.metricName || names.metricName || key;
if (!currentNamespaces.hasOwnProperty(namespace)) currentNamespaces[namespace] = []

currentTimerMetrics.push({
currentNamespaces[namespace].push({
MetricName: metricName,
Unit: 'Milliseconds',
Timestamp: new Date(timestamp * 1000).toISOString(),
Expand All @@ -187,10 +190,12 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) {
}
}

this.batchSend(currentTimerMetrics, namespace);
for (namespace in currentNamespaces){
this.batchSend(currentNamespaces[namespace], namespace);
}

// put all currently accumulated gauge metrics into an array
var currentGaugeMetrics = [];
currentNamespaces = {};
for (key in gauges) {

if (this.isBlacklisted(key)) {
Expand All @@ -200,19 +205,22 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) {
var names = this.config.processKeyForNamespace ? this.processKey(key) : {};
namespace = this.config.namespace || names.namespace || "AwsCloudWatchStatsdBackend";
var metricName = this.config.metricName || names.metricName || key;
if (!currentNamespaces.hasOwnProperty(namespace)) currentNamespaces[namespace] = []

currentGaugeMetrics.push({
currentNamespaces[namespace].push({
MetricName: metricName,
Unit: 'None',
Timestamp: new Date(timestamp * 1000).toISOString(),
Value: gauges[key]
});
}

this.batchSend(currentGaugeMetrics, namespace);
for (namespace in currentNamespaces){
this.batchSend(currentNamespaces[namespace], namespace);
}

// put all currently accumulated set metrics into an array
var currentSetMetrics = [];
currentNamespaces = {};
for (key in sets) {

if (this.isBlacklisted(key)) {
Expand All @@ -222,16 +230,19 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) {
var names = this.config.processKeyForNamespace ? this.processKey(key) : {};
namespace = this.config.namespace || names.namespace || "AwsCloudWatchStatsdBackend";
var metricName = this.config.metricName || names.metricName || key;
if (!currentNamespaces.hasOwnProperty(namespace)) currentNamespaces[namespace] = []

currentSetMetrics.push({
currentNamespaces[namespace].push({
MetricName: metricName,
Unit: 'None',
Timestamp: new Date(timestamp * 1000).toISOString(),
Value: sets[key].values().length
});
}

this.batchSend(currentSetMetrics, namespace);
for (namespace in currentNamespaces){
this.batchSend(currentNamespaces[namespace], namespace);
}
};

exports.init = function(startupTime, config, events) {
Expand Down