Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.ceilometerDashboard', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ngLodash', |
| 7 | 'ui.router', |
| 8 | 'xos.helpers', |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 9 | 'ngAnimate', |
Matteo Scandolo | c058211 | 2015-12-09 16:09:59 -0800 | [diff] [blame] | 10 | 'chart.js', |
| 11 | 'ui.bootstrap.accordion' |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 12 | ]) |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 13 | .config(($stateProvider, $urlRouterProvider) => { |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 14 | $stateProvider |
| 15 | .state('ceilometerDashboard', { |
| 16 | url: '/', |
| 17 | template: '<ceilometer-dashboard></ceilometer-dashboard>' |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 18 | }) |
| 19 | .state('samples', { |
| 20 | url: '/:name/:tenant/samples', |
| 21 | template: '<ceilometer-samples></ceilometer-samples>' |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 22 | }); |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 23 | $urlRouterProvider.otherwise('/'); |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 24 | }) |
| 25 | .config(function($httpProvider){ |
| 26 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 27 | }) |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 28 | .run(function($rootScope){ |
| 29 | $rootScope.stateName = 'ceilometerDashboard'; |
| 30 | $rootScope.$on('$stateChangeStart', (event, toState) => { |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 31 | $rootScope.stateName = toState.name; |
| 32 | }) |
| 33 | }) |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 34 | .service('Ceilometer', function($http, $q, lodash){ |
Matteo Scandolo | 2b6583e | 2015-12-08 15:24:23 -0800 | [diff] [blame] | 35 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 36 | this.getMappings = () => { |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 37 | let deferred = $q.defer(); |
| 38 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 39 | $http.get('/xoslib/xos-slice-service-mapping/') |
| 40 | .then((res) => { |
| 41 | deferred.resolve(res.data) |
| 42 | }) |
| 43 | .catch((e) => { |
| 44 | deferred.reject(e); |
| 45 | }); |
| 46 | |
| 47 | return deferred.promise; |
| 48 | } |
| 49 | |
| 50 | this.getMeters = (params) => { |
| 51 | let deferred = $q.defer(); |
| 52 | |
| 53 | $http.get('/xoslib/meters/', {cache: true, params: params}) |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 54 | // $http.get('../meters_mock.json', {cache: true}) |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 55 | .then((res) => { |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 56 | deferred.resolve(res.data) |
| 57 | }) |
| 58 | .catch((e) => { |
| 59 | deferred.reject(e); |
| 60 | }); |
| 61 | |
| 62 | return deferred.promise; |
| 63 | } |
| 64 | |
| 65 | this.getSamples = (name, tenant) => { |
| 66 | let deferred = $q.defer(); |
| 67 | |
Matteo Scandolo | ac812bd | 2015-12-07 17:32:39 -0800 | [diff] [blame] | 68 | $http.get(`/xoslib/metersamples/`, {params: {meter: name, tenant: tenant}}) |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 69 | .then((res) => { |
| 70 | deferred.resolve(res.data) |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 71 | }) |
| 72 | .catch((e) => { |
| 73 | deferred.reject(e); |
| 74 | }); |
| 75 | |
| 76 | return deferred.promise; |
| 77 | } |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 78 | |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 79 | this.getStats = (options) => { |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 80 | let deferred = $q.defer(); |
| 81 | |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 82 | $http.get('/xoslib/meterstatistics/', {cache: true, params: options}) |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 83 | // $http.get('../stats_mock.son', {cache: true}) |
| 84 | .then((res) => { |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 85 | deferred.resolve(res.data); |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 86 | }) |
| 87 | .catch((e) => { |
| 88 | deferred.reject(e); |
| 89 | }); |
| 90 | |
| 91 | return deferred.promise; |
| 92 | }; |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 93 | |
| 94 | // hold dashboard status (opened service, slice, resource) |
| 95 | this.selectedService = null; |
| 96 | this.selectedSlice = null; |
| 97 | this.selectedResource = null; |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 98 | }) |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 99 | .directive('ceilometerDashboard', function(lodash){ |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 100 | return { |
| 101 | restrict: 'E', |
| 102 | scope: {}, |
| 103 | bindToController: true, |
| 104 | controllerAs: 'vm', |
| 105 | templateUrl: 'templates/ceilometer-dashboard.tpl.html', |
| 106 | controller: function(Ceilometer){ |
| 107 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 108 | this.showStats = false; |
| 109 | |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 110 | // this open the accordion |
| 111 | this.accordion = { |
| 112 | open: {} |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Open the active panel base on the service stored values |
| 117 | */ |
| 118 | this.openPanels = () => { |
| 119 | if(Ceilometer.selectedService){ |
| 120 | this.accordion.open[Ceilometer.selectedService] = true; |
| 121 | if(Ceilometer.selectedSlice){ |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 122 | this.loadSliceMeter(Ceilometer.selectedSlice, Ceilometer.selectedService); |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 123 | this.selectedSlice = Ceilometer.selectedSlice; |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 124 | if(Ceilometer.selectedResource){ |
| 125 | this.selectedResource = Ceilometer.selectedResource; |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 131 | /** |
| 132 | * Load the list of service and slices |
| 133 | */ |
| 134 | |
| 135 | this.loadMappings = () => { |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 136 | this.loader = true; |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 137 | Ceilometer.getMappings() |
| 138 | .then((services) => { |
| 139 | this.services = services; |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 140 | this.openPanels(); |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 141 | }) |
| 142 | .catch(err => { |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 143 | this.error = (err.data && err.data.detail) ? err.data.detail : 'An Error occurred. Please try again later.'; |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 144 | }) |
| 145 | .finally(() => { |
| 146 | this.loader = false; |
| 147 | }); |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 148 | }; |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 149 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 150 | this.loadMappings(); |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 151 | |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 152 | /** |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 153 | * Load the list of a single slice |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 154 | */ |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 155 | |
| 156 | this.loadSliceMeter = (slice, service_name) => { |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 157 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 158 | Ceilometer.selectedSlice = null; |
| 159 | Ceilometer.selectedService = null; |
| 160 | Ceilometer.selectedResources = null; |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 161 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 162 | // visualization info |
| 163 | this.loader = true; |
| 164 | this.selectedSlice = slice.slice; |
| 165 | this.selectedTenant = slice.project_id; |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 166 | |
| 167 | // store the status |
| 168 | Ceilometer.selectedSlice = slice; |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 169 | Ceilometer.selectedService = service_name; |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 170 | |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 171 | Ceilometer.getMeters({tenant: slice.project_id}) |
| 172 | .then((sliceMeters) => { |
| 173 | this.selectedResources = lodash.groupBy(sliceMeters, 'resource_name'); |
| 174 | |
| 175 | // hacky |
| 176 | if(Ceilometer.selectedResource){ |
| 177 | this.selectedMeters = this.selectedResources[Ceilometer.selectedResource]; |
| 178 | } |
| 179 | }) |
| 180 | .catch(err => { |
| 181 | this.error = (err.data && err.data.detail) ? err.data.detail : 'An Error occurred. Please try again later.'; |
| 182 | }) |
| 183 | .finally(() => { |
| 184 | this.loader = false; |
| 185 | }); |
| 186 | }; |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * Select Meters for a resource |
| 190 | * |
| 191 | * @param Array meters The list of selected resources |
| 192 | * @returns void |
| 193 | */ |
| 194 | this.selectedMeters = null; |
| 195 | this.selectMeters = (meters, resource) => { |
| 196 | this.selectedMeters = meters; |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 197 | |
| 198 | Ceilometer.selectedResource = resource; |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 199 | this.selectedResource = resource; |
| 200 | } |
| 201 | |
Matteo Scandolo | 68c2e72 | 2015-12-04 10:14:40 -0800 | [diff] [blame] | 202 | } |
| 203 | }; |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 204 | }) |
| 205 | .directive('ceilometerSamples', function(lodash, $stateParams){ |
| 206 | return { |
| 207 | restrict: 'E', |
Matteo Scandolo | 895b30a | 2016-02-02 16:04:31 -0800 | [diff] [blame] | 208 | scope: {}, |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 209 | bindToController: true, |
| 210 | controllerAs: 'vm', |
| 211 | templateUrl: 'templates/ceilometer-samples.tpl.html', |
| 212 | controller: function(Ceilometer) { |
| 213 | |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 214 | // console.log(Ceilometer.selectResource); |
| 215 | |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 216 | this.chartColors = [ |
Matteo Scandolo | 2b6583e | 2015-12-08 15:24:23 -0800 | [diff] [blame] | 217 | '#286090', |
| 218 | '#F7464A', |
| 219 | '#46BFBD', |
| 220 | '#FDB45C', |
| 221 | '#97BBCD', |
| 222 | '#4D5360', |
| 223 | '#8c4f9f' |
| 224 | ]; |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 225 | |
| 226 | this.chart = { |
| 227 | series: [], |
| 228 | labels: [], |
| 229 | data: [] |
| 230 | } |
| 231 | |
| 232 | Chart.defaults.global.colours = this.chartColors; |
Matteo Scandolo | 2b6583e | 2015-12-08 15:24:23 -0800 | [diff] [blame] | 233 | |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 234 | this.chartType = 'line'; |
| 235 | |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 236 | if($stateParams.name && $stateParams.tenant){ |
| 237 | this.name = $stateParams.name; |
| 238 | this.tenant = $stateParams.tenant; |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 239 | // TODO rename tenant in project_id |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 240 | } |
Matteo Scandolo | 1b9ffac | 2015-12-14 17:36:09 -0800 | [diff] [blame] | 241 | else{ |
| 242 | throw new Error('Missing Name and Tenant Params!'); |
| 243 | } |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 244 | |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 245 | /** |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 246 | * Goes trough the array and format date to be used as labels |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 247 | * |
| 248 | * @param Array data |
| 249 | * @returns Array a list of labels |
| 250 | */ |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 251 | |
Matteo Scandolo | 1d8627f | 2015-12-05 18:44:45 -0800 | [diff] [blame] | 252 | this.getLabels = (data) => { |
| 253 | return data.reduce((list, item) => { |
| 254 | let date = new Date(item.timestamp); |
| 255 | list.push(`${date.getHours()}:${(date.getMinutes()<10?'0':'') + date.getMinutes()}:${date.getSeconds()}`); |
| 256 | return list; |
| 257 | }, []); |
| 258 | }; |
| 259 | |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 260 | /** |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 261 | * Goes trough the array and return a flat array of values |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 262 | * |
| 263 | * @param Array data |
| 264 | * @returns Array a list of values |
| 265 | */ |
| 266 | |
Matteo Scandolo | 1d8627f | 2015-12-05 18:44:45 -0800 | [diff] [blame] | 267 | this.getData = (data) => { |
| 268 | return data.reduce((list, item) => { |
| 269 | list.push(item.volume); |
| 270 | return list; |
| 271 | }, []); |
| 272 | } |
| 273 | |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 274 | /** |
| 275 | * Add a samples to the chart |
| 276 | * |
| 277 | * @param string resource_id |
| 278 | */ |
| 279 | this.chartMeters = []; |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 280 | this.addMeterToChart = (project_id) => { |
| 281 | this.chart['labels'] = this.getLabels(lodash.sortBy(this.samplesList[project_id], 'timestamp')); |
| 282 | this.chart['series'].push(project_id); |
| 283 | this.chart['data'].push(this.getData(lodash.sortBy(this.samplesList[project_id], 'timestamp'))); |
| 284 | this.chartMeters.push(this.samplesList[project_id][0]); //use the 0 as are all samples for the same resource and I need the name |
| 285 | lodash.remove(this.sampleLabels, {id: project_id}); |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Matteo Scandolo | e5d5ebd | 2015-12-14 14:42:28 -0800 | [diff] [blame] | 288 | this.removeFromChart = (meter) => { |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 289 | this.chart.data.splice(this.chart.series.indexOf(meter.project_id), 1); |
| 290 | this.chart.series.splice(this.chart.series.indexOf(meter.project_id), 1); |
| 291 | this.chartMeters.splice(lodash.findIndex(this.chartMeters, {project_id: meter.project_id}), 1); |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 292 | this.sampleLabels.push({ |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 293 | id: meter.project_id, |
| 294 | name: meter.resource_name || meter.project_id |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 295 | }) |
| 296 | }; |
| 297 | |
| 298 | /** |
| 299 | * Format samples to create a list of labels and ids |
| 300 | */ |
| 301 | |
| 302 | this.formatSamplesLabels = (samples) => { |
| 303 | |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 304 | return lodash.uniq(samples, 'project_id') |
Matteo Scandolo | 5074ccd | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 305 | .reduce((labels, item) => { |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 306 | labels.push({ |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 307 | id: item.project_id, |
| 308 | name: item.resource_name || item.project_id |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 309 | }); |
| 310 | return labels; |
Matteo Scandolo | 5074ccd | 2015-12-15 08:16:56 -0800 | [diff] [blame] | 311 | }, []); |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 315 | /** |
| 316 | * Load the samples and format data |
| 317 | */ |
| 318 | |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 319 | this.showSamples = () => { |
| 320 | this.loader = true; |
Matteo Scandolo | 6885608 | 2015-12-08 14:35:55 -0800 | [diff] [blame] | 321 | // Ceilometer.getSamples(this.name, this.tenant) //fetch one |
| 322 | Ceilometer.getSamples(this.name) //fetch all |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 323 | .then(res => { |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 324 | |
| 325 | // setup data for visualization |
Matteo Scandolo | 6c6b928 | 2015-12-15 14:37:27 -0800 | [diff] [blame] | 326 | this.samplesList = lodash.groupBy(res, 'project_id'); |
Matteo Scandolo | 324df09 | 2015-12-08 16:39:57 -0800 | [diff] [blame] | 327 | this.sampleLabels = this.formatSamplesLabels(res); |
| 328 | |
| 329 | // add current meter to chart |
| 330 | this.addMeterToChart(this.tenant); |
| 331 | |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 332 | }) |
| 333 | .catch(err => { |
Matteo Scandolo | c8f18e6 | 2015-12-09 15:23:51 -0800 | [diff] [blame] | 334 | this.error = err.data.detail; |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 335 | }) |
| 336 | .finally(() => { |
| 337 | this.loader = false; |
| 338 | }); |
| 339 | }; |
| 340 | |
| 341 | this.showSamples(); |
Matteo Scandolo | 7b80d84 | 2015-12-04 15:55:20 -0800 | [diff] [blame] | 342 | } |
| 343 | } |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 344 | }) |
| 345 | .directive('ceilometerStats', function(){ |
| 346 | return { |
| 347 | restrict: 'E', |
| 348 | scope: { |
| 349 | name: '=name', |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 350 | tenant: '=tenant' |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 351 | }, |
| 352 | bindToController: true, |
| 353 | controllerAs: 'vm', |
| 354 | templateUrl: 'templates/ceilometer-stats.tpl.html', |
| 355 | controller: function($scope, Ceilometer) { |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 356 | |
| 357 | this.getStats = (tenant) => { |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 358 | this.loader = true; |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 359 | Ceilometer.getStats({tenant: tenant}) |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 360 | .then(res => { |
| 361 | this.stats = res; |
| 362 | }) |
| 363 | .catch(err => { |
| 364 | this.error = err.data; |
| 365 | }) |
| 366 | .finally(() => { |
| 367 | this.loader = false; |
| 368 | }); |
| 369 | }; |
| 370 | |
Matteo Scandolo | 19c2a4e | 2016-02-02 16:29:40 -0800 | [diff] [blame] | 371 | $scope.$watch(() => this.name, (val) => { |
| 372 | if(val){ |
| 373 | this.getStats(this.tenant); |
| 374 | } |
| 375 | }); |
Matteo Scandolo | 41f5c15 | 2015-12-09 17:09:55 -0800 | [diff] [blame] | 376 | } |
| 377 | } |
Matteo Scandolo | 9db064f | 2016-02-08 14:17:42 -0800 | [diff] [blame] | 378 | }); |