You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2016/03/03 18:08:44 UTC
ambari git commit: AMBARI-15278. Templatized dashboards for specific
components - Grafana (Prajwal Rao via yusaku)
Repository: ambari
Updated Branches:
refs/heads/trunk 008503e12 -> e336ee02c
AMBARI-15278. Templatized dashboards for specific components - Grafana (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/e336ee02
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e336ee02
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e336ee02
Branch: refs/heads/trunk
Commit: e336ee02c537e15a68a1b7c34a0fafe04f2e0c0f
Parents: 008503e
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Thu Mar 3 09:08:19 2016 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Thu Mar 3 09:08:19 2016 -0800
----------------------------------------------------------------------
.../ambari-metrics/datasource.js | 71 ++++++++++++++++----
1 file changed, 59 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e336ee02/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 6553008..855caaa 100644
--- a/ambari-metrics/ambari-metrics-grafana/ambari-metrics/datasource.js
+++ b/ambari-metrics/ambari-metrics-grafana/ambari-metrics/datasource.js
@@ -136,8 +136,19 @@ define([
);
};
//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 templatedHosts = templateSrv.variables.filter(function(o) {
+ return o.name === "hosts"
+ });
+ var templatedHost = (_.isEmpty(templateSrv.variables)) ? '' : templatedHosts[0].options.filter(function(host) {
+ return host.selected;
+ }).map(function(hostName) {
+ return hostName.value;
+ });
+
+ var tComponents = _.isEmpty(templateSrv.variables) ? '' : templateSrv.variables.filter(function(variable) {
+ return variable.name === "components"
+ });
+ var tComponent = _.isEmpty(tComponents) ? '' : tComponents[0].current.value;
var getServiceAppIdData = function(target) {
var tHost = (_.isEmpty(templateSrv.variables)) ? templatedHost : target.templatedHost;
@@ -156,8 +167,9 @@ define([
var metricsPromises = [];
if (!_.isEmpty(templateSrv.variables)) {
- if (!_.isEmpty(_.find(templatedHost, function (o) { return o === "*"; }))) {
- var allHost = templateSrv.variables[0].options.filter(function(all) {
+ if (!_.isEmpty(_.find(templatedHost, function (wildcard) { return wildcard === "*"; }))) {
+ var allHosts = templateSrv.variables.filter(function(variable) { return variable.name === "hosts"});
+ var allHost = allHosts[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) {
@@ -214,27 +226,62 @@ define([
/**
* AMS Datasource Templating Variables.
*/
- AmbariMetricsDatasource.prototype.metricFindQuery = function (query) {
+ AmbariMetricsDatasource.prototype.metricFindQuery = function(query) {
var interpolated;
try {
interpolated = templateSrv.replace(query);
} catch (err) {
return $q.reject(err);
}
- return this.doAmbariRequest({
+ var tComponents = _.isEmpty(templateSrv.variables) ? '' : templateSrv.variables.filter(function(variable) {
+ return variable.name === "components"
+ });
+ var tComponent = _.isEmpty(tComponents) ? '' : tComponents[0].current.value;
+ if (!tComponent) {
+ return this.doAmbariRequest({
method: 'GET',
url: '/ws/v1/timeline/metrics/' + interpolated
- })
- .then(function (results) {
+ }).then(function(results) {
+ //Remove fakehostname from the list of hosts on the cluster.
+ var fake = "fakehostname";
+ delete results.data[fake];
+ return _.map(_.keys(results.data), function(hostName) {
+ return {
+ text: hostName,
+ expandable: hostName.expandable ? true : false
+ };
+ });
+ });
+ } else {
+ return this.doAmbariRequest({
+ method: 'GET',
+ url: '/ws/v1/timeline/metrics/hosts'
+ }).then(function(results) {
+ var compToHostMap = {};
//Remove fakehostname from the list of hosts on the cluster.
var fake = "fakehostname"; delete results.data[fake];
- return _.map(_.keys(results.data), function (hostName) {
+ //Query hosts based on component name
+ _.forEach(results.data, function(comp, hostName) {
+ comp.forEach(function(component) {
+ if (!compToHostMap[component]) {
+ compToHostMap[component] = [];
+ }
+ compToHostMap[component].push(hostName);
+ });
+ });
+ var compHosts = compToHostMap[tComponent];
+ compHosts = _.map(compHosts, function(host) {
return {
- text: hostName,
- expandable: hostName.expandable ? true : false
- };
+ text: host,
+ expandable: host.expandable ? true : false
+ };
+ });
+ compHosts = _.sortBy(compHosts, function(i) {
+ return i.text.toLowerCase();
});
+ return $q.when(compHosts);
});
+ }
};
/**