From 144c52e0fda5c973728bb6a073e1ac6e3922ab6e Mon Sep 17 00:00:00 2001 From: Jeremy Mitchell Date: Mon, 24 Jul 2017 13:16:24 -0600 Subject: [PATCH] implements configurable autorefresh or dashboard components --- .../WidgetCacheGroupsController.js | 33 +++++++++- .../capacity/WidgetCapacityController.js | 26 +++++++- .../cdnChart/WidgetCDNChartController.js | 27 +++++++- .../widget/routing/WidgetRoutingController.js | 26 +++++++- .../monitor/dashboard/DashboardController.js | 66 ++++++++++++++++++- .../app/src/traffic_portal_properties.json | 25 +++++++ 6 files changed, 193 insertions(+), 10 deletions(-) diff --git a/traffic_portal/app/src/common/modules/widget/cacheGroups/WidgetCacheGroupsController.js b/traffic_portal/app/src/common/modules/widget/cacheGroups/WidgetCacheGroupsController.js index 43cda0771d..78fdbc05f4 100644 --- a/traffic_portal/app/src/common/modules/widget/cacheGroups/WidgetCacheGroupsController.js +++ b/traffic_portal/app/src/common/modules/widget/cacheGroups/WidgetCacheGroupsController.js @@ -17,7 +17,29 @@ * under the License. */ -var WidgetCacheGroupsController = function(cacheGroupHealth, $scope, locationUtils) { +var WidgetCacheGroupsController = function(cacheGroupHealth, $scope, $interval, cacheGroupService, locationUtils, propertiesModel) { + + var interval, + autoRefresh = propertiesModel.properties.dashboard.autoRefresh; + + var getCacheGroupHealth = function() { + cacheGroupService.getCacheGroupHealth() + .then(function(result) { + $scope.cacheGroupHealth = result; + }); + }; + + var createInterval = function() { + killInterval(); + interval = $interval(function() { getCacheGroupHealth() }, propertiesModel.properties.dashboard.cacheGroupHealth.refreshRateInMS ); + }; + + var killInterval = function() { + if (angular.isDefined(interval)) { + $interval.cancel(interval); + interval = undefined; + } + }; // pagination $scope.currentCacheGroupsPage = 1; @@ -29,15 +51,22 @@ var WidgetCacheGroupsController = function(cacheGroupHealth, $scope, locationUti return (location.online / (location.online + location.offline)) * 100; }; + $scope.$on("$destroy", function() { + killInterval(); + }); + var init = function() { if (cacheGroupHealth) { // only set this if it's passed in $scope.cacheGroupHealth = cacheGroupHealth; } + if (autoRefresh) { + createInterval(); + } }; init(); }; -WidgetCacheGroupsController.$inject = ['cacheGroupHealth', '$scope', 'locationUtils']; +WidgetCacheGroupsController.$inject = ['cacheGroupHealth', '$scope', '$interval', 'cacheGroupService', 'locationUtils', 'propertiesModel']; module.exports = WidgetCacheGroupsController; diff --git a/traffic_portal/app/src/common/modules/widget/capacity/WidgetCapacityController.js b/traffic_portal/app/src/common/modules/widget/capacity/WidgetCapacityController.js index e7c57cbcb6..4f853eb8b2 100644 --- a/traffic_portal/app/src/common/modules/widget/capacity/WidgetCapacityController.js +++ b/traffic_portal/app/src/common/modules/widget/capacity/WidgetCapacityController.js @@ -17,7 +17,10 @@ * under the License. */ -var WidgetCapacityController = function($scope, cdnService) { +var WidgetCapacityController = function($scope, $interval, cdnService, propertiesModel) { + + var interval, + autoRefresh = propertiesModel.properties.dashboard.autoRefresh; var getCapacity = function() { cdnService.getCapacity() @@ -85,17 +88,36 @@ var WidgetCapacityController = function($scope, cdnService) { $.plot($("#capacityChart"), graphData, options); }; + var createInterval = function() { + killInterval(); + interval = $interval(function() { getCapacity() }, propertiesModel.properties.dashboard.capacity.refreshRateInMS ); + }; + + var killInterval = function() { + if (angular.isDefined(interval)) { + $interval.cancel(interval); + interval = undefined; + } + }; + $scope.availablePercent = 0; $scope.utilizedPercent = 0; $scope.maintenancePercent = 0; $scope.unavailablePercent = 0; + $scope.$on("$destroy", function() { + killInterval(); + }); + var init = function() { getCapacity(); + if (autoRefresh) { + createInterval(); + } }; init(); }; -WidgetCapacityController.$inject = ['$scope', 'cdnService']; +WidgetCapacityController.$inject = ['$scope', '$interval', 'cdnService', 'propertiesModel']; module.exports = WidgetCapacityController; diff --git a/traffic_portal/app/src/common/modules/widget/cdnChart/WidgetCDNChartController.js b/traffic_portal/app/src/common/modules/widget/cdnChart/WidgetCDNChartController.js index 286ba4e9f5..94d3f3db5e 100644 --- a/traffic_portal/app/src/common/modules/widget/cdnChart/WidgetCDNChartController.js +++ b/traffic_portal/app/src/common/modules/widget/cdnChart/WidgetCDNChartController.js @@ -17,11 +17,15 @@ * under the License. */ -var WidgetCDNChartController = function(cdn, $scope, $timeout, $filter, $q, cdnService, cacheStatsService, dateUtils, locationUtils, numberUtils) { +var WidgetCDNChartController = function(cdn, $scope, $timeout, $filter, $q, $interval, cdnService, cacheStatsService, dateUtils, locationUtils, numberUtils, propertiesModel) { var chartSeries, chartOptions; + var chartInterval, + autoRefresh = propertiesModel.properties.dashboard.autoRefresh; + + var getCDN = function(id) { cdnService.getCDN(id) .then(function(result) { @@ -151,6 +155,18 @@ var WidgetCDNChartController = function(cdn, $scope, $timeout, $filter, $q, cdnS }; + var createIntervals = function(cdnId) { + killIntervals(); + chartInterval = $interval(function() { getCDN(cdnId) }, propertiesModel.properties.dashboard.cdnChart.refreshRateInMS ); + }; + + var killIntervals = function() { + if (angular.isDefined(chartInterval)) { + $interval.cancel(chartInterval); + chartInterval = undefined; + } + }; + var registerResizeListener = function() { $(window).resize(plotChart); }; @@ -169,6 +185,10 @@ var WidgetCDNChartController = function(cdn, $scope, $timeout, $filter, $q, cdnS $scope.navigateToPath = locationUtils.navigateToPath; + $scope.$on("$destroy", function() { + killIntervals(); + }); + angular.element(document).ready(function () { var cdnId; if (cdn) { @@ -178,9 +198,12 @@ var WidgetCDNChartController = function(cdn, $scope, $timeout, $filter, $q, cdnS cdnId = $('#' + $scope.randomId).closest('.chartContainer').data('cdnid'); } getCDN(cdnId); + if (autoRefresh) { + createIntervals(cdnId); + } }); }; -WidgetCDNChartController.$inject = ['cdn', '$scope', '$timeout', '$filter', '$q', 'cdnService', 'cacheStatsService', 'dateUtils', 'locationUtils', 'numberUtils']; +WidgetCDNChartController.$inject = ['cdn', '$scope', '$timeout', '$filter', '$q', '$interval', 'cdnService', 'cacheStatsService', 'dateUtils', 'locationUtils', 'numberUtils', 'propertiesModel']; module.exports = WidgetCDNChartController; diff --git a/traffic_portal/app/src/common/modules/widget/routing/WidgetRoutingController.js b/traffic_portal/app/src/common/modules/widget/routing/WidgetRoutingController.js index da979482fa..da339f6350 100644 --- a/traffic_portal/app/src/common/modules/widget/routing/WidgetRoutingController.js +++ b/traffic_portal/app/src/common/modules/widget/routing/WidgetRoutingController.js @@ -17,7 +17,10 @@ * under the License. */ -var WidgetRoutingController = function($scope, cdnService) { +var WidgetRoutingController = function($scope, $interval, cdnService, propertiesModel) { + + var interval, + autoRefresh = propertiesModel.properties.dashboard.autoRefresh; var getRoutingMethods = function() { cdnService.getRoutingMethods() @@ -34,12 +37,31 @@ var WidgetRoutingController = function($scope, cdnService) { }); }; + var createInterval = function() { + killInterval(); + interval = $interval(function() { getRoutingMethods() }, propertiesModel.properties.dashboard.routing.refreshRateInMS ); + }; + + var killInterval = function() { + if (angular.isDefined(interval)) { + $interval.cancel(interval); + interval = undefined; + } + }; + + $scope.$on("$destroy", function() { + killInterval(); + }); + var init = function() { getRoutingMethods(); + if (autoRefresh) { + createInterval(); + } }; init(); }; -WidgetRoutingController.$inject = ['$scope', 'cdnService']; +WidgetRoutingController.$inject = ['$scope', '$interval', 'cdnService', 'propertiesModel']; module.exports = WidgetRoutingController; diff --git a/traffic_portal/app/src/modules/private/monitor/dashboard/DashboardController.js b/traffic_portal/app/src/modules/private/monitor/dashboard/DashboardController.js index c08a4e6191..b6f844667b 100644 --- a/traffic_portal/app/src/modules/private/monitor/dashboard/DashboardController.js +++ b/traffic_portal/app/src/modules/private/monitor/dashboard/DashboardController.js @@ -17,7 +17,58 @@ * under the License. */ -var DashboardController = function(cacheGroupHealth, cdns, currentStats, serverCount, $scope) { +var DashboardController = function(cacheGroupHealth, cdns, currentStats, serverCount, $scope, $interval, cacheGroupService, cdnService, serverService, propertiesModel) { + + var cacheGroupHealthInterval, + currentStatsInterval, + serverCountInterval, + autoRefresh = propertiesModel.properties.dashboard.autoRefresh; + + var getCacheGroupHealth = function() { + cacheGroupService.getCacheGroupHealth() + .then(function(result) { + $scope.cacheGroupHealth = result; + }); + }; + + var getCurrentStats = function() { + cdnService.getCurrentStats() + .then(function(result) { + $scope.totalStats = _.find(result.currentStats, function(item) { + // total stats are buried in a hash where cdn = total + return item.cdn == 'total'; + }); + }); + }; + + var getServerCount = function() { + serverService.getStatusCount() + .then(function(result) { + $scope.serverCount = result; + }); + }; + + var createIntervals = function() { + killIntervals(); + cacheGroupHealthInterval = $interval(function() { getCacheGroupHealth() }, propertiesModel.properties.dashboard.healthyCacheCount.refreshRateInMS ); + currentStatsInterval = $interval(function() { getCurrentStats() }, propertiesModel.properties.dashboard.currentStats.refreshRateInMS ); + serverCountInterval = $interval(function() { getServerCount() }, propertiesModel.properties.dashboard.cacheStatusCount.refreshRateInMS ); + }; + + var killIntervals = function() { + if (angular.isDefined(cacheGroupHealthInterval)) { + $interval.cancel(cacheGroupHealthInterval); + cacheGroupHealthInterval = undefined; + } + if (angular.isDefined(currentStatsInterval)) { + $interval.cancel(currentStatsInterval); + currentStatsInterval = undefined; + } + if (angular.isDefined(serverCountInterval)) { + $interval.cancel(serverCountInterval); + serverCountInterval = undefined; + } + }; $scope.cacheGroupHealth = cacheGroupHealth; @@ -30,7 +81,18 @@ var DashboardController = function(cacheGroupHealth, cdns, currentStats, serverC $scope.serverCount = serverCount; + $scope.$on("$destroy", function() { + killIntervals(); + }); + + var init = function () { + if (autoRefresh) { + createIntervals(); + } + }; + init(); + }; -DashboardController.$inject = ['cacheGroupHealth', 'cdns', 'currentStats', 'serverCount', '$scope']; +DashboardController.$inject = ['cacheGroupHealth', 'cdns', 'currentStats', 'serverCount', '$scope', '$interval', 'cacheGroupService', 'cdnService', 'serverService', 'propertiesModel']; module.exports = DashboardController; diff --git a/traffic_portal/app/src/traffic_portal_properties.json b/traffic_portal/app/src/traffic_portal_properties.json index d7c7a4e788..85b7c5e3f6 100644 --- a/traffic_portal/app/src/traffic_portal_properties.json +++ b/traffic_portal/app/src/traffic_portal_properties.json @@ -2,6 +2,31 @@ "_comment": "These are the default properties for Traffic Portal. To customize these values, create your own traffic_portal_properties.json and copy to your web root replacing the existing one.", "properties": { "name": "Traffic Portal", + "dashboard": { + "_comments": "These are configurable properties for the dashboard", + "autoRefresh": true, + "currentStats": { + "refreshRateInMS": 30000 + }, + "healthyCacheCount": { + "refreshRateInMS": 60000 + }, + "cacheStatusCount": { + "refreshRateInMS": 60000 + }, + "cdnChart": { + "refreshRateInMS": 60000 + }, + "capacity": { + "refreshRateInMS": 60000 + }, + "routing": { + "refreshRateInMS": 60000 + }, + "cacheGroupHealth": { + "refreshRateInMS": 60000 + } + }, "customMenu": { "_comments": "These are custom items you want to add to the menu. 'items' is an array of hashes where each hash has 'name' (the menu item name), 'embed' (true|false to determine if content is embedded in TP or not), and 'url' (the url of the content)", "name": "Other",