You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/02/18 14:33:26 UTC

[07/33] ambari git commit: AMBARI-14999. Multi-host option for Templated Dashboards. (Prajwal Rao via yusaku)

AMBARI-14999. Multi-host option for Templated Dashboards. (Prajwal Rao via yusaku)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1e510f59
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1e510f59
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1e510f59

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 1e510f590f9caa9ef7fb4e71e9badd54cb36b5c0
Parents: f41fccf
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Tue Feb 16 12:15:43 2016 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Tue Feb 16 12:15:43 2016 -0800

----------------------------------------------------------------------
 ambari-metrics/ambari-metrics-grafana/README.md |  22 ++++++++-
 .../ambari-metrics/datasource.js                |  49 +++++++++++++++----
 .../screenshots/21-multi-templating.png         | Bin 0 -> 92034 bytes
 3 files changed, 60 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1e510f59/ambari-metrics/ambari-metrics-grafana/README.md
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-grafana/README.md b/ambari-metrics/ambari-metrics-grafana/README.md
index 7eb84a7..af2b5cb 100644
--- a/ambari-metrics/ambari-metrics-grafana/README.md
+++ b/ambari-metrics/ambari-metrics-grafana/README.md
@@ -33,10 +33,12 @@ Use **ambari-metrics** to visualize metrics exposed via AMS in Grafana.
  - [Save Dashboard](#savedash)
  - [Time Ranges](#timerange)
  - [Edit Panel/Graph](#editpanel)
+ - [Templated Dashboards](#templating)
+    - [Multi Host Templated Dashboards](#multi-templating)
 
 
 ----------
-![enter image description here](screenshots/full-dashboard.png)
+![Full Dashboard](screenshots/full-dashboard.png)
 
 ----------
 <a name="installg"></a>
@@ -257,7 +259,23 @@ http://GRAFANA_HOST:3000
 > 10. When you now add a graph, and select your component and metric, the plotted graph will show you metrics for the selected hostname from the dropdown.
 > 11. The legend on the graph will also now update with the selected host.
 
-**Templalted dashboards do support multiple metrics in a single graph.** 
+**Templated dashboards do support multiple metrics in a single graph.** 
 
 
 ![Templating](screenshots/20-templating.png)
+
+---
+
+<a name="multi-templating"></a>
+### Multi Host Templated Dashboards.
+
+**Templated dashboards now have the ability to filter graphs based on a single host or multiple hosts.**
+
+> 1. Once you've created your templated dashboard, you can edit it gain by clicking on the "cog" on the top, select "Templating".
+> 2. Click on "Edit" for your templating variable.
+> 3. To be able to select Multiiple Hosts, set multi-value selection to "enable" and leave multi-format set to "glob".
+> 4. To have an option for All hosts, select All Value, and set it to "*" and All format to "wildcard".
+> 5. Hit Update and close the templating variables options and you should be now able to select multiple hosts from the dropdown (or "all" hosts at once.)
+
+
+![Multi Host Templating](screenshots/21-multi-templating.png)

http://git-wip-us.apache.org/repos/asf/ambari/blob/1e510f59/ambari-metrics/ambari-metrics-grafana/ambari-metrics/datasource.js
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-grafana/ambari-metrics/datasource.js b/ambari-metrics/ambari-metrics-grafana/ambari-metrics/datasource.js
index e89ad0e..ca7ea65 100644
--- a/ambari-metrics/ambari-metrics-grafana/ambari-metrics/datasource.js
+++ b/ambari-metrics/ambari-metrics-grafana/ambari-metrics/datasource.js
@@ -38,6 +38,7 @@ define([
         }
         var allMetrics = [];
         var appIds = [];
+        //We get a list of components and their associated metrics.
         AmbariMetricsDatasource.prototype.initMetricAppidMapping = function () {
           backendSrv.get(this.url + '/ws/v1/timeline/metrics/metadata')
             .then(function (items) {
@@ -73,7 +74,7 @@ define([
           }
 
           options.url = this.url + options.url;
-          options.inspect = {type: 'discovery'};
+          options.inspect = {type: 'ambarimetrics'};
 
           return backendSrv.datasourceRequest(options);
         };
@@ -82,6 +83,7 @@ define([
          * AMS Datasource  Query
          */
         AmbariMetricsDatasource.prototype.query = function (options) {
+
           var emptyData = function (metric) {
             return {
               data: {
@@ -99,6 +101,7 @@ define([
               }
               var series = [];
               var metricData = res.metrics[0].metrics;
+              // Added hostname to legend for templated dashboards.
               var hostLegend = res.metrics[0].hostname ? ' on ' + res.metrics[0].hostname : '';
               var timeSeries = {};
               if (target.hosts === undefined || target.hosts.trim() === "") {
@@ -122,7 +125,6 @@ define([
             };
 
           };
-
           var getHostAppIdData = function(target) {
             var precision = target.shouldAddPrecision ? '&precision=' + target.precision : '';
             var rate = target.shouldComputeRate ? '._rate._' : '._';
@@ -132,14 +134,16 @@ define([
                 getMetricsData(target)
             );
           };
+          //Check if it's a templated dashboard.
+          var templatedHost = (_.isEmpty(templateSrv.variables)) ? "" : templateSrv.variables[0].options.filter(function(host)
+              { return host.selected; }).map(function(hostName) { return hostName.value; });
 
           var getServiceAppIdData = function(target) {
-            var templatedHost = (_.isEmpty(templateSrv.variables)) ? "" : templateSrv.variables[0].options.filter(function(host)
-              { return host.selected; }).map(function(hostName) { return hostName.value; });
+            var tHost = (_.isEmpty(templateSrv.variables)) ? templatedHost : target.templatedHost;
             var precision = target.shouldAddPrecision ? '&precision=' + target.precision : '';
             var rate = target.shouldComputeRate ? '._rate._' : '._';
             return backendSrv.get(self.url + '/ws/v1/timeline/metrics?metricNames=' + target.metric + rate
-              + target.aggregator + '&hostname=' + templatedHost + '&appId=' + target.app + '&startTime=' + from +
+              + target.aggregator + '&hostname=' + tHost + '&appId=' + target.app + '&startTime=' + from +
               '&endTime=' + to + precision).then(
               getMetricsData(target)
             );
@@ -148,15 +152,43 @@ define([
           // Time Ranges
           var from = Math.floor(options.range.from.valueOf() / 1000);
           var to = Math.floor(options.range.to.valueOf() / 1000);
-          var metricsPromises = _.map(options.targets, function(target) {
+
+          var metricsPromises = [];
+          if (!_.isEmpty(templateSrv.variables)) {
+            if (!_.isEmpty(_.find(templatedHost, function (o) { return o === "*"; }))) {
+              var allHost = templateSrv.variables[0].options.filter(function(all) {
+                return all.text !== "All"; }).map(function(hostName) { return hostName.value; });
+              _.forEach(allHost, function(processHost) {
+              metricsPromises.push(_.map(options.targets, function(target) {
+                target.templatedHost = processHost;
+                console.debug('target app=' + target.app + ',' +
+                  'target metric=' + target.metric + ' on host=' + target.templatedHost);
+                return getServiceAppIdData(target);
+              }));
+            });
+            } else {
+              _.forEach(templatedHost, function(processHost) {
+              metricsPromises.push(_.map(options.targets, function(target) {
+                target.templatedHost = processHost;
+                console.debug('target app=' + target.app + ',' +
+                  'target metric=' + target.metric + ' on host=' + target.templatedHost);
+                return getServiceAppIdData(target);
+              }));
+            });
+            }
+
+            metricsPromises = _.flatten(metricsPromises);
+          } else {
+            metricsPromises = _.map(options.targets, function(target) {
               console.debug('target app=' + target.app + ',' +
-                'target metric=' + target.metric + ' on host=' + target.hosts);
+                'target metric=' + target.metric + ' on host=' + target.tempHost);
               if (!!target.hosts) {
                 return getHostAppIdData(target);
               } else {
                 return getServiceAppIdData(target);
               }
             });
+          }
 
           return $q.all(metricsPromises).then(function(metricsDataArray) {
             var data = _.map(metricsDataArray, function(metricsData) {
@@ -288,8 +320,7 @@ define([
           ]);
           return aggregatorsPromise;
         };
-
         return AmbariMetricsDatasource;
       });
     }
-);
\ No newline at end of file
+);

http://git-wip-us.apache.org/repos/asf/ambari/blob/1e510f59/ambari-metrics/ambari-metrics-grafana/screenshots/21-multi-templating.png
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-grafana/screenshots/21-multi-templating.png b/ambari-metrics/ambari-metrics-grafana/screenshots/21-multi-templating.png
new file mode 100644
index 0000000..9855302
Binary files /dev/null and b/ambari-metrics/ambari-metrics-grafana/screenshots/21-multi-templating.png differ