Skip to content

Commit 446acde

Browse files
committed
Merge pull request #9 from eyeem/feature/multi-region-support
add multi-region support
2 parents 77807cf + 5117e37 commit 446acde

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,40 @@ A preferable approach to obtaining account credentials is instead to query the M
122122
}
123123
}
124124

125+
## Multi-region support
126+
127+
If you wish to send cloudwatch metrics to multiple regions at once, instead of
128+
129+
{
130+
backends: [ "aws-cloudwatch-statsd-backend" ],
131+
cloudwatch:
132+
{
133+
accessKeyId: 'YOUR_ACCESS_KEY_ID',
134+
secretAccessKey:'YOUR_SECRET_ACCESS_KEY',
135+
region:"YOUR_REGION"
136+
}
137+
}
138+
139+
you can use the `instances` key under `cloudwatch` to configure a list of configurations.
140+
141+
{
142+
backends: ["aws-cloudwatch-statsd-backend"],
143+
cloudwatch: {
144+
instances: [{
145+
accessKeyId: 'YOUR_ACCESS_KEY_ID',
146+
secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',
147+
region: "YOUR_REGION_1",
148+
whitelist: ['YOUR_FULL_METRIC_NAME1']
149+
}, {
150+
accessKeyId: 'YOUR_ACCESS_KEY_ID',
151+
secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',
152+
region: "YOUR_REGION_2",
153+
whitelist: ['YOUR_FULL_METRIC_NAME2']
154+
}]
155+
}
156+
}
157+
158+
125159
## Tutorial
126160

127161
This project was launched with a following [blog post/tutorial](http://blog.simpletask.se/post/aggregating-monitoring-statistics-for-aws-cloudwatch) describing the implementation chain from log4net to Cloudwatch on a Windows system.

lib/aws-cloudwatch-statsd-backend.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ var AWS = require('aws-sdk');
44
function CloudwatchBackend(startupTime, config, emitter){
55
var self = this;
66

7-
this.config = config.cloudwatch || {};
7+
this.config = config || {};
88
AWS.config = this.config;
99

1010
function setEmitter() {
11-
self.cloudwatch = new AWS.CloudWatch(AWS.config);
11+
self.cloudwatch = new AWS.CloudWatch(self.config);
1212
emitter.on('flush', function(timestamp, metrics) { self.flush(timestamp, metrics); });
1313
}
1414

@@ -19,7 +19,7 @@ function CloudwatchBackend(startupTime, config, emitter){
1919
ms = new AWS.EC2MetadataCredentials();
2020
ms.refresh(function(err) {
2121
if(err) { console.log('Failed to fetch IAM role credentials: '+err); }
22-
AWS.config.credentials = ms;
22+
self.config.credentials = ms;
2323
setEmitter();
2424
});
2525
} else {
@@ -29,7 +29,7 @@ function CloudwatchBackend(startupTime, config, emitter){
2929
var data = JSON.parse(rdata);
3030

3131
if(err) { console.log('Failed to fetch IAM role credentials: '+err); }
32-
AWS.config.credentials = new AWS.Credentials(data.AccessKeyId, data.SecretAccessKey, data.Token);
32+
self.config.credentials = new AWS.Credentials(data.AccessKeyId, data.SecretAccessKey, data.Token);
3333
setEmitter();
3434
});
3535
}
@@ -194,6 +194,12 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) {
194194
};
195195

196196
exports.init = function(startupTime, config, events) {
197-
var instance = new CloudwatchBackend(startupTime, config, events);
197+
var cloudwatch = config.cloudwatch || {};
198+
var instances = cloudwatch.instances || [cloudwatch];
199+
for (key in instances) {
200+
instanceConfig = instances[key];
201+
console.log("Starting cloudwatch reporter instance in region:", instanceConfig.region);
202+
var instance = new CloudwatchBackend(startupTime, instanceConfig, events);
203+
}
198204
return true;
199205
};

0 commit comments

Comments
 (0)