Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for multi-namespace #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
@@ -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)
@@ -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) {

@@ -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(),
@@ -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)) {
@@ -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)) {
@@ -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) {