This repository was archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcloudwatch.js
37 lines (35 loc) · 1.5 KB
/
cloudwatch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module.exports = function (service) {
var aws = require ('aws-lib');
cw = aws.createCWClient(service.from.id, service.from.secret);
var now = new Date,
start = new Date(now.getTime() - 1 * 60 * 1000); // 1 min ago
return function(funneler) {
for (var serviceName in service.services) {
var thisService = service.services[serviceName];
(function (serviceName, thisService) {
cw.call(
"GetMetricStatistics",
{
EndTime: now.toISOString(),
StartTime: start.toISOString(),
Namespace: thisService.namespace,
MetricName: thisService.metric,
'Statistics.member.1': thisService.type,
'Dimensions.member.1.Name': thisService.name,
'Dimensions.member.1.Value': thisService.value,
Unit: thisService.unit,
Period: 60,
},
function(err, result) {
funneler({
'funnel': 'cloudwatch',
'nodeName': thisService.value,
'metricName': serviceName,
'reading': result.GetMetricStatisticsResult.Datapoints.member[thisService.type]
});
}
);
})(serviceName, thisService);
}
}
};