-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
39 lines (33 loc) · 1.04 KB
/
index.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
37
38
39
'use strict';
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function AwsCloudwatchMetricsReport(opts) {
this.file = opts.file || 'metric_data.json';
}
AwsCloudwatchMetricsReport.prototype.onStart = function (root, context) {
this.contentWriter = context.writer.writeFile(this.file);
var summary = root.getCoverageSummary();
var metrics = [];
var timestamp = new Date();
for (var dimension in summary.data) {
for (var metricType in summary.data[dimension]) {
var metric = {
MetricName: capitalizeFirstLetter(metricType),
Dimensions: [
{
Name: 'Coverage',
Value: capitalizeFirstLetter(dimension),
},
],
Timestamp: timestamp,
Unit: metricType === 'pct' ? 'Percent' : 'Count',
Value: summary[dimension][metricType],
};
metrics.push(metric);
}
}
this.contentWriter.write(JSON.stringify(metrics));
this.contentWriter.close();
};
module.exports = AwsCloudwatchMetricsReport;