From c0c8465ec2166471a4ffd8d076d9a452e91d5644 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Mon, 24 Aug 2015 21:58:57 +0900 Subject: [PATCH] add loading custom metrics definitions --- .../datasource/cloudwatch/datasource.js | 41 +++++++++++++++++++ .../cloudwatch/partials/config.html | 13 +++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index 6018f5f9e77..61507dbfb06 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -172,6 +172,47 @@ function (angular, _, kbn) { ], }; /* jshint +W101 */ + + /* load custom metrics definitions */ + var self = this; + $q.all( + _.map(datasource.jsonData.customMetricsAttributes, function(u) { + return $http({ method: 'GET', url: u }); + }) + ) + .then(function(allResponse) { + _.chain(allResponse) + .map(function(d) { + return d.data.Metrics; + }) + .flatten() + .reject(function(metric) { + return metric.Namespace.indexOf('AWS/') === 0; + }) + .map(function(metric) { + metric.Dimensions = _.chain(metric.Dimensions) + .map(function(d) { + return d.Name; + }) + .value().sort(); + return metric; + }) + .uniq(function(metric) { + return metric.Namespace + metric.MetricName + metric.Dimensions.join(''); + }) + .each(function(metric) { + if (!_.has(self.supportedMetrics, metric.Namespace)) { + self.supportedMetrics[metric.Namespace] = []; + } + self.supportedMetrics[metric.Namespace].push(metric.MetricName); + + if (!_.has(self.supportedDimensions, metric.Namespace)) { + self.supportedDimensions[metric.Namespace] = []; + } + + self.supportedDimensions[metric.Namespace] = _.union(self.supportedDimensions[metric.Namespace], metric.Dimensions); + }); + }); } // Called once per panel (graph) diff --git a/public/app/plugins/datasource/cloudwatch/partials/config.html b/public/app/plugins/datasource/cloudwatch/partials/config.html index a936994b681..668d817c905 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/config.html +++ b/public/app/plugins/datasource/cloudwatch/partials/config.html @@ -19,7 +19,7 @@
-
+
  • Access Key Id @@ -37,3 +37,14 @@
+
+
    +
  • + Custom Metrics Attributes +
  • +
  • + +
  • +
+
+