Repository: incubator-griffin Updated Branches: refs/heads/master 990dd4f33 -> 38978a8c6
Metric2 update ui of metric again Author: Yang <[email protected]> Closes #33 from RachelYang2/metric2. Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/38978a8c Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/38978a8c Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/38978a8c Branch: refs/heads/master Commit: 38978a8c6a7689fdf1fc8cd5d8e090532b6417e8 Parents: 990dd4f Author: Yang <[email protected]> Authored: Thu May 18 13:57:58 2017 +0800 Committer: Liu <[email protected]> Committed: Thu May 18 13:57:58 2017 +0800 ---------------------------------------------------------------------- ui/js/controllers/health-ctrl.js | 112 +++++++++++++++++++++++++++------ ui/js/controllers/metrics-ctrl.js | 35 ++++++----- ui/js/controllers/sidebar-ctrl.js | 43 ++++++------- ui/js/services/services.js | 7 ++- 4 files changed, 138 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/38978a8c/ui/js/controllers/health-ctrl.js ---------------------------------------------------------------------- diff --git a/ui/js/controllers/health-ctrl.js b/ui/js/controllers/health-ctrl.js index 019f26a..3c0c662 100644 --- a/ui/js/controllers/health-ctrl.js +++ b/ui/js/controllers/health-ctrl.js @@ -1,16 +1,16 @@ /* - Copyright (c) 2016 eBay Software Foundation. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Copyright (c) 2016 eBay Software Foundation. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ define(['./module'], function (controllers) { 'use strict'; @@ -23,18 +23,82 @@ define(['./module'], function (controllers) { pageInit(); + $scope.orgs = []; + $scope.dataData = []; + $scope.finalData = []; function pageInit() { $scope.$emit('initReq'); - var url = $config.uri.heatmap; - $http.get(url).success(function(res) { - renderTreeMap(res); +// var url = $config.uri.heatmap; + var url_dashboard = $config.uri.dashboard ; + var url_organization = $config.uri.organization; + $http.get(url_organization).success(function(res){ + var orgNode = null; + angular.forEach(res, function(value,key) { + orgNode = new Object(); + $scope.orgs.push(orgNode); + orgNode.name = key; + orgNode.assetMap = value; + }); + $scope.originalOrgs = angular.copy($scope.orgs); + $http.post(url_dashboard, {"query": {"match_all":{}}, "sort": [{"tmst": {"order": "asc"}}],"size":1000}).success(function(data) { + angular.forEach(data.hits.hits, function(sys) { + var chartData = sys._source; + chartData.sort = function(a,b){ + return a.tmst - b.tmst; + } + }); + $scope.originalData = angular.copy(data); + + $scope.myData = angular.copy($scope.originalData.hits.hits); + $scope.metricName = []; + for(var i = 0;i<$scope.myData.length;i++){ + $scope.metricName.push($scope.myData[i]._source.name); + } + $scope.metricNameUnique = []; + angular.forEach($scope.metricName,function(name){ + if($scope.metricNameUnique.indexOf(name) === -1){ + $scope.dataData[$scope.metricNameUnique.length] = new Array(); + $scope.metricNameUnique.push(name); + } + }); + + for(var i = 0;i<$scope.myData.length;i++){ + for(var j = 0 ;j<$scope.metricNameUnique.length;j++){ + if($scope.myData[i]._source.name==$scope.metricNameUnique[j]){ + $scope.dataData[j].push($scope.myData[i]); + } + } + } + angular.forEach($scope.originalOrgs,function(sys,parentIndex){ + var node = null; + node = new Object(); + node.name = sys.name; + node.dq = 0; + node.metrics = new Array(); + angular.forEach($scope.dataData,function(metric,index){ + if(sys.assetMap.indexOf(metric[metric.length-1]._source.name)!= -1){ + var metricNode = new Object(); + metricNode.name = metric[metric.length-1]._source.name; + metricNode.timestamp = metric[metric.length-1]._source.tmst; + metricNode.dq = metric[metric.length-1]._source.matched/metric[metric.length-1]._source.total*100; + metricNode.details = new Array(); + node.metrics.push(metricNode); + } + }) + $scope.finalData.push(node); + }) + $scope.originalData = angular.copy($scope.finalData); + renderTreeMap($scope.finalData); + }); + }); +// $http.get(url).success(function(res) { +// renderTreeMap(res); +// }); } function renderTreeMap(res) { - - function parseData(data) { var sysId = 0; var metricId = 0; @@ -169,9 +233,17 @@ define(['./module'], function (controllers) { } var showBig = function(metricName){ - var metricDetailUrl = $config.uri.metricdetail + '/' + metricName; - $http.get(metricDetailUrl).success(function (data){ - $rootScope.showBigChart($barkChart.getOptionBig(data)); + var metricDetailUrl = $config.uri.dashboard; + $http.post(metricDetailUrl, {"query": { "bool":{"filter":[ {"term" : {"name": metricName }}]}}, "sort": [{"tmst": {"order": "asc"}}],"size":1000}).success(function(data) { + var metric = new Object(); + metric.name = data.hits.hits[0]._source.name; + metric.timestamp = data.hits.hits[data.hits.hits.length-1]._source.tmst; + metric.dq = data.hits.hits[data.hits.hits.length-1]._source.matched/data.hits.hits[data.hits.hits.length-1]._source.matched*100; + metric.details = new Array(); + angular.forEach(data.hits.hits,function(point){ + metric.details.push(point); + }) + $rootScope.showBigChart($barkChart.getOptionBig(metric)); }); } http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/38978a8c/ui/js/controllers/metrics-ctrl.js ---------------------------------------------------------------------- diff --git a/ui/js/controllers/metrics-ctrl.js b/ui/js/controllers/metrics-ctrl.js index a81d820..b2ca82e 100644 --- a/ui/js/controllers/metrics-ctrl.js +++ b/ui/js/controllers/metrics-ctrl.js @@ -37,9 +37,7 @@ define(['./module'], function(controllers) { orgNode.assetMap = value; }); $scope.originalOrgs = angular.copy($scope.orgs); - var url_briefmetrics = $config.uri.dashboard; - $http.post(url_dashboard, {"query": {"match_all":{}}, "sort": [{"tmst": {"order": "asc"}}], "size": 1000}).success(function(data) { - $scope.briefmetrics = data; + $http.post(url_dashboard, {"query": {"match_all":{}}, "sort": [{"tmst": {"order": "asc"}}],"size":1000}).success(function(data) { angular.forEach(data.hits.hits, function(sys) { var chartData = sys._source; chartData.sort = function(a,b){ @@ -76,30 +74,39 @@ define(['./module'], function(controllers) { node.dq = 0; node.metrics = new Array(); angular.forEach($scope.dataData,function(metric,index){ - if(sys.assetMap.indexOf(metric[0]._source.name)!= -1){ + if(sys.assetMap.indexOf(metric[metric.length-1]._source.name)!= -1){ var metricNode = new Object(); - metricNode.name = metric[0]._source.name; - metricNode.timestamp = metric[0]._source.tmst; var dq = 0.0; - if (metric[0]._source.total > 0) dq = metric[0]._source.matched/metric[0]._source.total*100; + if (metric[metric.length-1]._source.total > 0) + dq = metric[metric.length-1]._source.matched/metric[metric.length-1]._source.total*100; metricNode.dq = dq; + metricNode.name = metric[metric.length-1]._source.name; + metricNode.timestamp = metric[metric.length-1]._source.tmst; metricNode.details = angular.copy(metric); node.metrics.push(metricNode); } }) $scope.finalData.push(node); }) -// if(!sysName){ -// $scope.backup_metrics = angular.copy(res); -// } + $scope.originalData = angular.copy($scope.finalData); + + if($routeParams.sysName && $scope.originalData && $scope.originalData.length > 0){ + for(var i = 0; i < $scope.originalData.length; i ++){ + if($scope.originalData[i].name == $routeParams.sysName){ + $scope.selectedOrgIndex = i; + $scope.changeOrg(); + $scope.orgSelectDisabled = true; + break; + } + + } + } $timeout(function() { redraw($scope.finalData); }); - $scope.originalData = angular.copy($scope.finalData); }); - }); -// $http.post(url_dashboard, {"query": {"match_all":{}},"size":1000}).success(function(res) { + });// $http.post(url_dashboard, {"query": {"match_all":{}},"size":1000}).success(function(res) { } $scope.$watch('selectedOrgIndex', function(newValue){ @@ -142,7 +149,7 @@ define(['./module'], function(controllers) { $scope.changeAsset = function() { $scope.finalData = []; - if($scope.selectedOrgIndex == ""){ + if($scope.selectedOrgIndex === ""){ $scope.finalData = angular.copy($scope.originalData); } else { var org = angular.copy($scope.originalData[$scope.selectedOrgIndex]); http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/38978a8c/ui/js/controllers/sidebar-ctrl.js ---------------------------------------------------------------------- diff --git a/ui/js/controllers/sidebar-ctrl.js b/ui/js/controllers/sidebar-ctrl.js index 9d0f65d..7cf4945 100644 --- a/ui/js/controllers/sidebar-ctrl.js +++ b/ui/js/controllers/sidebar-ctrl.js @@ -22,7 +22,7 @@ define(['./module'], function(controllers) { $scope.orgs = []; $scope.finalData = []; - $scope.dataData = []; + $scope.metricData = []; var renderDataAssetPie = function(status) { resizePieChart(); @@ -39,11 +39,6 @@ define(['./module'], function(controllers) { $scope.$watch(function(){return $routeParams.sysName;}, function(value){ console.log('Watched value: ' + value); - if(value){ - sideBarList(value); - }else{ - $scope.briefmetrics = $scope.backup_metrics; - } }); $scope.draw = function(metric, parentIndex, index) { @@ -77,14 +72,13 @@ define(['./module'], function(controllers) { }); $scope.originalOrg = angular.copy($scope.orgs); var url_briefmetrics = $config.uri.dashboard; - $http.get(url_briefmetrics, {cache:true}).success(function(data) { - $scope.briefmetrics = data; + $http.post(url_briefmetrics, {"query": {"match_all":{}}, "sort": [{"tmst": {"order": "asc"}}],"size":1000}).success(function(data) { angular.forEach(data.hits.hits, function(sys) { var chartData = sys._source; chartData.sort = function(a,b){ return a.tmst - b.tmst; } - }); + }); $scope.originalData = angular.copy(data); $scope.myData = angular.copy($scope.originalData.hits.hits); $scope.metricName = []; @@ -94,7 +88,7 @@ define(['./module'], function(controllers) { $scope.metricNameUnique = []; angular.forEach($scope.metricName,function(name){ if($scope.metricNameUnique.indexOf(name) === -1){ - $scope.dataData[$scope.metricNameUnique.length] = new Array(); + $scope.metricData[$scope.metricNameUnique.length] = new Array(); $scope.metricNameUnique.push(name); } }); @@ -103,7 +97,7 @@ define(['./module'], function(controllers) { //push every point to its metric for(var j = 0 ;j<$scope.metricNameUnique.length;j++){ if($scope.myData[i]._source.name==$scope.metricNameUnique[j]){ - $scope.dataData[j].push($scope.myData[i]); + $scope.metricData[j].push($scope.myData[i]); } } } @@ -113,26 +107,27 @@ define(['./module'], function(controllers) { node.name = sys.name; node.dq = 0; node.metrics = new Array(); - angular.forEach($scope.dataData,function(metric,index){ - if(sys.assetMap.indexOf(metric[0]._source.name)!= -1){ + angular.forEach($scope.metricData,function(metric,index){ + if(sys.assetMap.indexOf(metric[metric.length-1]._source.name)!= -1){ var metricNode = new Object(); - metricNode.name = metric[0]._source.name; - metricNode.timestamp = metric[0]._source.tmst; - metricNode.dq = metric[0]._source.matched/metric[0]._source.total*100; + metricNode.name = metric[metric.length-1]._source.name; + metricNode.timestamp = metric[metric.length-1]._source.tmst; + metricNode.dq = metric[metric.length-1]._source.matched/metric[metric.length-1]._source.total*100; metricNode.details = angular.copy(metric); node.metrics.push(metricNode); } }); $scope.finalData.push(node); - }) -// if(!sysName){ -// $scope.backup_metrics = angular.copy(res); -// } - $timeout(function() { - resizeSideChart(); - }, 0); }); - }); + + if(!sysName){ + $scope.backup_metrics = angular.copy($scope.finalData); + } + $timeout(function() { + resizeSideChart(); + }, 0); + }); + }); } $(window).resize(function() { http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/38978a8c/ui/js/services/services.js ---------------------------------------------------------------------- diff --git a/ui/js/services/services.js b/ui/js/services/services.js index c089637..1083e17 100644 --- a/ui/js/services/services.js +++ b/ui/js/services/services.js @@ -3,7 +3,10 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,6 +25,7 @@ define(['./module'], function (services) { // var BACKEND_SERVER = 'http://localhost:8080'; var BACKEND_SERVER = ''; var API_ROOT_PATH = '/api/v1'; + // var ES_SERVER = 'http://10.149.247.156:59200'; // var ES_SERVER = "http://" + location.host + ":59200" var ES_SERVER = "http://" + location.host.replace("8080", "9200"); @@ -58,7 +62,8 @@ define(['./module'], function (services) { metricsByOrg:'', // organization:'/org.json', // dashboard:'/dashboard.json', - organization: BACKEND_SERVER + '/orgWithMetrics', + + organization:BACKEND_SERVER + '/orgWithMetrics', dashboard:ES_SERVER+'/griffin/accuracy/_search?pretty&filter_path=hits.hits._source', metricsample: BACKEND_SERVER + API_ROOT_PATH + '/metrics/sample', metricdownload: BACKEND_SERVER + API_ROOT_PATH + '/metrics/download',
