Просмотр исходного кода

add loading custom metrics definitions

Mitsuhiro Tanda 10 лет назад
Родитель
Сommit
c0c8465ec2

+ 41 - 0
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)

+ 12 - 1
public/app/plugins/datasource/cloudwatch/partials/config.html

@@ -19,7 +19,7 @@
   </ul>
   <div class="clearfix"></div>
 </div>
-<div class="tight-form last" ng-show="current.jsonData.access === 'direct'">
+<div class="tight-form" ng-show="current.jsonData.access === 'direct'">
   <ul class="tight-form-list">
     <li class="tight-form-item" style="width: 80px">
       Access Key Id
@@ -37,3 +37,14 @@
   </ul>
   <div class="clearfix"></div>
 </div>
+<div class="tight-form last">
+  <ul class="tight-form-list">
+    <li class="tight-form-item" style="width: 80px">
+      Custom Metrics Attributes
+    </li>
+    <li>
+      <input type="text" class="tight-form-input input-xlarge" ng-model='current.jsonData.customMetricsAttributes[0]' ng-init="current.jsonData.customMetricsAttributes = current.jsonData.customMetricsAttributes || []" placeholder="" required></input>
+    </li>
+  </ul>
+  <div class="clearfix"></div>
+</div>