##// END OF EJS Templates
frontend: do not close non-existing websocket connection - don't do anything if window is not focused
ergo -
Show More
@@ -1,694 +1,700 b''
1 // # Copyright (C) 2010-2016 RhodeCode GmbH
1 // # Copyright (C) 2010-2016 RhodeCode GmbH
2 // #
2 // #
3 // # This program is free software: you can redistribute it and/or modify
3 // # This program is free software: you can redistribute it and/or modify
4 // # it under the terms of the GNU Affero General Public License, version 3
4 // # it under the terms of the GNU Affero General Public License, version 3
5 // # (only), as published by the Free Software Foundation.
5 // # (only), as published by the Free Software Foundation.
6 // #
6 // #
7 // # This program is distributed in the hope that it will be useful,
7 // # This program is distributed in the hope that it will be useful,
8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // # GNU General Public License for more details.
10 // # GNU General Public License for more details.
11 // #
11 // #
12 // # You should have received a copy of the GNU Affero General Public License
12 // # You should have received a copy of the GNU Affero General Public License
13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 // #
14 // #
15 // # This program is dual-licensed. If you wish to learn more about the
15 // # This program is dual-licensed. If you wish to learn more about the
16 // # App Enlight Enterprise Edition, including its added features, Support
16 // # App Enlight Enterprise Edition, including its added features, Support
17 // # services, and proprietary license terms, please see
17 // # services, and proprietary license terms, please see
18 // # https://rhodecode.com/licenses/
18 // # https://rhodecode.com/licenses/
19
19
20 angular.module('appenlight.controllers')
20 angular.module('appenlight.controllers')
21 .controller('IndexDashboardController', IndexDashboardController);
21 .controller('IndexDashboardController', IndexDashboardController);
22
22
23 IndexDashboardController.$inject = ['$scope', '$location','$cookies', '$interval', 'stateHolder', 'userSelfPropertyResource', 'applicationsPropertyResource', 'AeConfig', 'AeUser'];
23 IndexDashboardController.$inject = ['$scope', '$location','$cookies', '$interval', 'stateHolder', 'userSelfPropertyResource', 'applicationsPropertyResource', 'AeConfig', 'AeUser'];
24
24
25 function IndexDashboardController($scope, $location, $cookies, $interval, stateHolder, userSelfPropertyResource, applicationsPropertyResource, AeConfig, AeUser) {
25 function IndexDashboardController($scope, $location, $cookies, $interval, stateHolder, userSelfPropertyResource, applicationsPropertyResource, AeConfig, AeUser) {
26 var vm = this;
26 var vm = this;
27 stateHolder.section = 'dashboard';
27 stateHolder.section = 'dashboard';
28 vm.timeOptions = {};
28 vm.timeOptions = {};
29 var allowed = ['1h', '4h', '12h', '24h', '1w', '2w', '1M'];
29 var allowed = ['1h', '4h', '12h', '24h', '1w', '2w', '1M'];
30 _.each(allowed, function (key) {
30 _.each(allowed, function (key) {
31 if (allowed.indexOf(key) !== -1) {
31 if (allowed.indexOf(key) !== -1) {
32 vm.timeOptions[key] = AeConfig.timeOptions[key];
32 vm.timeOptions[key] = AeConfig.timeOptions[key];
33 }
33 }
34 });
34 });
35 vm.urls = AeConfig.urls;
35 vm.urls = AeConfig.urls;
36 vm.applications = AeUser.applications_map;
36 vm.applications = AeUser.applications_map;
37 vm.show_dashboard = false;
37 vm.show_dashboard = false;
38 vm.resource = null;
38 vm.resource = null;
39 vm.graphType = {selected: null};
39 vm.graphType = {selected: null};
40 vm.timeSpan = vm.timeOptions['1h'];
40 vm.timeSpan = vm.timeOptions['1h'];
41 vm.trendingReports = [];
41 vm.trendingReports = [];
42 vm.exceptions = 0;
42 vm.exceptions = 0;
43 vm.satisfyingRequests = 0;
43 vm.satisfyingRequests = 0;
44 vm.toleratedRequests = 0;
44 vm.toleratedRequests = 0;
45 vm.frustratingRequests = 0;
45 vm.frustratingRequests = 0;
46 vm.uptimeStats = 0;
46 vm.uptimeStats = 0;
47 vm.apdexStats = [];
47 vm.apdexStats = [];
48 vm.seriesRequestsData = [];
48 vm.seriesRequestsData = [];
49 vm.seriesMetricsData = [];
49 vm.seriesMetricsData = [];
50 vm.seriesSlowData = [];
50 vm.seriesSlowData = [];
51 vm.slowCalls = [];
51 vm.slowCalls = [];
52 vm.slowURIS = [];
52 vm.slowURIS = [];
53
53
54 vm.reportChartConfig = {
54 vm.reportChartConfig = {
55 data: {
55 data: {
56 json: [],
56 json: [],
57 xFormat: '%Y-%m-%dT%H:%M:%S'
57 xFormat: '%Y-%m-%dT%H:%M:%S'
58 },
58 },
59 color: {
59 color: {
60 pattern: ['#6baed6', '#e6550d', '#74c476', '#fdd0a2', '#8c564b']
60 pattern: ['#6baed6', '#e6550d', '#74c476', '#fdd0a2', '#8c564b']
61 },
61 },
62 axis: {
62 axis: {
63 x: {
63 x: {
64 type: 'timeseries',
64 type: 'timeseries',
65 tick: {
65 tick: {
66 culling: {
66 culling: {
67 max: 6 // the number of tick texts will be adjusted to less than this value
67 max: 6 // the number of tick texts will be adjusted to less than this value
68 },
68 },
69 format: '%Y-%m-%d %H:%M'
69 format: '%Y-%m-%d %H:%M'
70 }
70 }
71 },
71 },
72 y: {
72 y: {
73 tick: {
73 tick: {
74 count: 5,
74 count: 5,
75 format: d3.format('.2s')
75 format: d3.format('.2s')
76 }
76 }
77 }
77 }
78 },
78 },
79 subchart: {
79 subchart: {
80 show: true,
80 show: true,
81 size: {
81 size: {
82 height: 20
82 height: 20
83 }
83 }
84 },
84 },
85 size: {
85 size: {
86 height: 250
86 height: 250
87 },
87 },
88 zoom: {
88 zoom: {
89 rescale: true
89 rescale: true
90 },
90 },
91 grid: {
91 grid: {
92 x: {
92 x: {
93 show: true
93 show: true
94 },
94 },
95 y: {
95 y: {
96 show: true
96 show: true
97 }
97 }
98 },
98 },
99 tooltip: {
99 tooltip: {
100 format: {
100 format: {
101 title: function (d) {
101 title: function (d) {
102 return '' + d;
102 return '' + d;
103 },
103 },
104 value: function (v) {
104 value: function (v) {
105 return v
105 return v
106 }
106 }
107 }
107 }
108 }
108 }
109 };
109 };
110 vm.reportChartData = {};
110 vm.reportChartData = {};
111
111
112 vm.reportSlowChartConfig = {
112 vm.reportSlowChartConfig = {
113 data: {
113 data: {
114 json: [],
114 json: [],
115 xFormat: '%Y-%m-%dT%H:%M:%S'
115 xFormat: '%Y-%m-%dT%H:%M:%S'
116 },
116 },
117 color: {
117 color: {
118 pattern: ['#6baed6', '#e6550d', '#74c476', '#fdd0a2', '#8c564b']
118 pattern: ['#6baed6', '#e6550d', '#74c476', '#fdd0a2', '#8c564b']
119 },
119 },
120 axis: {
120 axis: {
121 x: {
121 x: {
122 type: 'timeseries',
122 type: 'timeseries',
123 tick: {
123 tick: {
124 culling: {
124 culling: {
125 max: 6 // the number of tick texts will be adjusted to less than this value
125 max: 6 // the number of tick texts will be adjusted to less than this value
126 },
126 },
127 format: '%Y-%m-%d %H:%M'
127 format: '%Y-%m-%d %H:%M'
128 }
128 }
129 },
129 },
130 y: {
130 y: {
131 tick: {
131 tick: {
132 count: 5,
132 count: 5,
133 format: d3.format('.2s')
133 format: d3.format('.2s')
134 }
134 }
135 }
135 }
136 },
136 },
137 subchart: {
137 subchart: {
138 show: true,
138 show: true,
139 size: {
139 size: {
140 height: 20
140 height: 20
141 }
141 }
142 },
142 },
143 size: {
143 size: {
144 height: 250
144 height: 250
145 },
145 },
146 zoom: {
146 zoom: {
147 rescale: true
147 rescale: true
148 },
148 },
149 grid: {
149 grid: {
150 x: {
150 x: {
151 show: true
151 show: true
152 },
152 },
153 y: {
153 y: {
154 show: true
154 show: true
155 }
155 }
156 },
156 },
157 tooltip: {
157 tooltip: {
158 format: {
158 format: {
159 title: function (d) {
159 title: function (d) {
160 return '' + d;
160 return '' + d;
161 },
161 },
162 value: function (v) {
162 value: function (v) {
163 return v
163 return v
164 }
164 }
165 }
165 }
166 }
166 }
167 };
167 };
168 vm.reportSlowChartData = {};
168 vm.reportSlowChartData = {};
169
169
170 vm.metricsChartConfig = {
170 vm.metricsChartConfig = {
171 data: {
171 data: {
172 json: [],
172 json: [],
173 xFormat: '%Y-%m-%dT%H:%M:%S',
173 xFormat: '%Y-%m-%dT%H:%M:%S',
174 keys: {
174 keys: {
175 x: 'x',
175 x: 'x',
176 value: ["main", "sql", "nosql", "tmpl", "remote", "custom"]
176 value: ["main", "sql", "nosql", "tmpl", "remote", "custom"]
177 },
177 },
178 names: {
178 names: {
179 main: 'View/Application logic',
179 main: 'View/Application logic',
180 sql: 'Relational database queries',
180 sql: 'Relational database queries',
181 nosql: 'NoSql datastore calls',
181 nosql: 'NoSql datastore calls',
182 tmpl: 'Template rendering',
182 tmpl: 'Template rendering',
183 custom: 'Custom timed calls',
183 custom: 'Custom timed calls',
184 remote: 'Requests to remote resources'
184 remote: 'Requests to remote resources'
185 },
185 },
186 type: 'area',
186 type: 'area',
187 groups: [["main", "sql", "nosql", "remote", "custom", "tmpl"]],
187 groups: [["main", "sql", "nosql", "remote", "custom", "tmpl"]],
188 order: null
188 order: null
189 },
189 },
190 color: {
190 color: {
191 pattern: ['#6baed6', '#c7e9c0', '#fd8d3c', '#d6616b', '#ffcc00', '#c6dbef']
191 pattern: ['#6baed6', '#c7e9c0', '#fd8d3c', '#d6616b', '#ffcc00', '#c6dbef']
192 },
192 },
193 axis: {
193 axis: {
194 x: {
194 x: {
195 type: 'timeseries',
195 type: 'timeseries',
196 tick: {
196 tick: {
197 culling: {
197 culling: {
198 max: 6 // the number of tick texts will be adjusted to less than this value
198 max: 6 // the number of tick texts will be adjusted to less than this value
199 },
199 },
200 format: '%Y-%m-%d %H:%M'
200 format: '%Y-%m-%d %H:%M'
201 }
201 }
202 },
202 },
203 y: {
203 y: {
204 tick: {
204 tick: {
205 count: 5,
205 count: 5,
206 format: d3.format('.2f')
206 format: d3.format('.2f')
207 }
207 }
208 }
208 }
209 },
209 },
210 point: {
210 point: {
211 show: false
211 show: false
212 },
212 },
213 subchart: {
213 subchart: {
214 show: true,
214 show: true,
215 size: {
215 size: {
216 height: 20
216 height: 20
217 }
217 }
218 },
218 },
219 size: {
219 size: {
220 height: 350
220 height: 350
221 },
221 },
222 zoom: {
222 zoom: {
223 rescale: true
223 rescale: true
224 },
224 },
225 grid: {
225 grid: {
226 x: {
226 x: {
227 show: true
227 show: true
228 },
228 },
229 y: {
229 y: {
230 show: true
230 show: true
231 }
231 }
232 },
232 },
233 tooltip: {
233 tooltip: {
234 format: {
234 format: {
235 title: function (d) {
235 title: function (d) {
236 return '' + d;
236 return '' + d;
237 },
237 },
238 value: function (v) {
238 value: function (v) {
239 return v
239 return v
240 }
240 }
241 }
241 }
242 }
242 }
243 };
243 };
244 vm.metricsChartData = {};
244 vm.metricsChartData = {};
245
245
246 vm.responseChartConfig = {
246 vm.responseChartConfig = {
247 data: {
247 data: {
248 json: [],
248 json: [],
249 xFormat: '%Y-%m-%dT%H:%M:%S'
249 xFormat: '%Y-%m-%dT%H:%M:%S'
250 },
250 },
251 color: {
251 color: {
252 pattern: ['#d6616b', '#6baed6', '#fd8d3c']
252 pattern: ['#d6616b', '#6baed6', '#fd8d3c']
253 },
253 },
254 axis: {
254 axis: {
255 x: {
255 x: {
256 type: 'timeseries',
256 type: 'timeseries',
257 tick: {
257 tick: {
258 culling: {
258 culling: {
259 max: 6 // the number of tick texts will be adjusted to less than this value
259 max: 6 // the number of tick texts will be adjusted to less than this value
260 },
260 },
261 format: '%Y-%m-%d %H:%M'
261 format: '%Y-%m-%d %H:%M'
262 }
262 }
263 },
263 },
264 y: {
264 y: {
265 tick: {
265 tick: {
266 count: 5,
266 count: 5,
267 format: d3.format('.2f')
267 format: d3.format('.2f')
268 }
268 }
269 }
269 }
270 },
270 },
271 point: {
271 point: {
272 show: false
272 show: false
273 },
273 },
274 subchart: {
274 subchart: {
275 show: true,
275 show: true,
276 size: {
276 size: {
277 height: 20
277 height: 20
278 }
278 }
279 },
279 },
280 size: {
280 size: {
281 height: 350
281 height: 350
282 },
282 },
283 zoom: {
283 zoom: {
284 rescale: true
284 rescale: true
285 },
285 },
286 grid: {
286 grid: {
287 x: {
287 x: {
288 show: true
288 show: true
289 },
289 },
290 y: {
290 y: {
291 show: true
291 show: true
292 }
292 }
293 },
293 },
294 tooltip: {
294 tooltip: {
295 format: {
295 format: {
296 title: function (d) {
296 title: function (d) {
297 return '' + d;
297 return '' + d;
298 },
298 },
299 value: function (v) {
299 value: function (v) {
300 return v
300 return v
301 }
301 }
302 }
302 }
303 }
303 }
304 };
304 };
305 vm.responseChartData = {};
305 vm.responseChartData = {};
306
306
307 vm.requestsChartConfig = {
307 vm.requestsChartConfig = {
308 data: {
308 data: {
309 json: [],
309 json: [],
310 xFormat: '%Y-%m-%dT%H:%M:%S'
310 xFormat: '%Y-%m-%dT%H:%M:%S'
311 },
311 },
312 color: {
312 color: {
313 pattern: ['#d6616b', '#6baed6', '#fd8d3c']
313 pattern: ['#d6616b', '#6baed6', '#fd8d3c']
314 },
314 },
315 axis: {
315 axis: {
316 x: {
316 x: {
317 type: 'timeseries',
317 type: 'timeseries',
318 tick: {
318 tick: {
319 culling: {
319 culling: {
320 max: 6 // the number of tick texts will be adjusted to less than this value
320 max: 6 // the number of tick texts will be adjusted to less than this value
321 },
321 },
322 format: '%Y-%m-%d %H:%M'
322 format: '%Y-%m-%d %H:%M'
323 }
323 }
324 },
324 },
325 y: {
325 y: {
326 tick: {
326 tick: {
327 count: 5,
327 count: 5,
328 format: d3.format('.2f')
328 format: d3.format('.2f')
329 }
329 }
330 }
330 }
331 },
331 },
332 point: {
332 point: {
333 show: false
333 show: false
334 },
334 },
335 subchart: {
335 subchart: {
336 show: true,
336 show: true,
337 size: {
337 size: {
338 height: 20
338 height: 20
339 }
339 }
340 },
340 },
341 size: {
341 size: {
342 height: 350
342 height: 350
343 },
343 },
344 zoom: {
344 zoom: {
345 rescale: true
345 rescale: true
346 },
346 },
347 grid: {
347 grid: {
348 x: {
348 x: {
349 show: true
349 show: true
350 },
350 },
351 y: {
351 y: {
352 show: true
352 show: true
353 }
353 }
354 },
354 },
355 tooltip: {
355 tooltip: {
356 format: {
356 format: {
357 title: function (d) {
357 title: function (d) {
358 return '' + d;
358 return '' + d;
359 },
359 },
360 value: function (v) {
360 value: function (v) {
361 return v
361 return v
362 }
362 }
363 }
363 }
364 }
364 }
365 };
365 };
366 vm.requestsChartData = {};
366 vm.requestsChartData = {};
367
367
368 vm.loading = {
368 vm.loading = {
369 'apdex': true,
369 'apdex': true,
370 'reports': true,
370 'reports': true,
371 'graphs': true,
371 'graphs': true,
372 'slowCalls': true,
372 'slowCalls': true,
373 'slowURIS': true,
373 'slowURIS': true,
374 'requestsBreakdown': true,
374 'requestsBreakdown': true,
375 'series': true
375 'series': true
376 };
376 };
377 vm.stream = {paused: false, filtered: false, messages: [], reports: []};
377 vm.stream = {paused: false, filtered: false, messages: [], reports: []};
378 vm.websocket = null;
378 vm.websocket = null;
379 userSelfPropertyResource.get({key: 'websocket'}, function (data) {
379 userSelfPropertyResource.get({key: 'websocket'}, function (data) {
380 console.log(data);
380 console.log(data);
381 console.log(AeConfig.ws_url + '/ws?conn_id=' + data.conn_id);
381 console.log(AeConfig.ws_url + '/ws?conn_id=' + data.conn_id);
382 vm.websocket = new ReconnectingWebSocket(AeConfig.ws_url + '/ws?conn_id=' + data.conn_id);
382 vm.websocket = new ReconnectingWebSocket(AeConfig.ws_url + '/ws?conn_id=' + data.conn_id);
383 vm.websocket.onopen = function (event) {
383 vm.websocket.onopen = function (event) {
384 console.log('open');
384 console.log('open');
385 };
385 };
386 vm.websocket.onmessage = function (event) {
386 vm.websocket.onmessage = function (event) {
387 var data = JSON.parse(event.data);
387 var data = JSON.parse(event.data);
388 console.log('message');
388 console.log('message');
389 $scope.$apply(function (scope) {
389 $scope.$apply(function (scope) {
390 _.each(data, function (message) {
390 _.each(data, function (message) {
391 if (message.type === 'message'){
391 if (message.type === 'message'){
392 ws_report = message.message.report;
392 ws_report = message.message.report;
393 if (ws_report.http_status != 500) {
393 if (ws_report.http_status != 500) {
394 return
394 return
395 }
395 }
396 if (vm.stream.paused == true) {
396 if (vm.stream.paused == true) {
397 return
397 return
398 }
398 }
399 if (vm.stream.filtered && ws_report.resource_id != vm.resource) {
399 if (vm.stream.filtered && ws_report.resource_id != vm.resource) {
400 return
400 return
401 }
401 }
402 var should_insert = true;
402 var should_insert = true;
403 _.each(vm.stream.reports, function (report) {
403 _.each(vm.stream.reports, function (report) {
404 if (report.report_id == ws_report.report_id) {
404 if (report.report_id == ws_report.report_id) {
405 report.occurences = ws_report.occurences;
405 report.occurences = ws_report.occurences;
406 should_insert = false;
406 should_insert = false;
407 }
407 }
408 });
408 });
409 if (should_insert) {
409 if (should_insert) {
410 if (vm.stream.reports.length > 7) {
410 if (vm.stream.reports.length > 7) {
411 vm.stream.reports.pop();
411 vm.stream.reports.pop();
412 }
412 }
413 vm.stream.reports.unshift(ws_report);
413 vm.stream.reports.unshift(ws_report);
414 }
414 }
415 }
415 }
416 });
416 });
417 });
417 });
418 };
418 };
419 vm.websocket.onclose = function (event) {
419 vm.websocket.onclose = function (event) {
420 console.log('closed');
420 console.log('closed');
421 };
421 };
422
422
423 vm.websocket.onerror = function (event) {
423 vm.websocket.onerror = function (event) {
424 console.log('error');
424 console.log('error');
425 };
425 };
426
426
427 });
427 });
428
428
429 vm.determineStartState = function () {
429 vm.determineStartState = function () {
430 if (AeUser.applications.length) {
430 if (AeUser.applications.length) {
431 vm.resource = Number($location.search().resource);
431 vm.resource = Number($location.search().resource);
432
432
433 if (!vm.resource){
433 if (!vm.resource){
434 var cookieResource = $cookies.getObject('resource');
434 var cookieResource = $cookies.getObject('resource');
435 console.log('cookieResource', cookieResource);
435 console.log('cookieResource', cookieResource);
436
436
437 if (cookieResource) {
437 if (cookieResource) {
438 vm.resource = cookieResource;
438 vm.resource = cookieResource;
439 }
439 }
440 else{
440 else{
441 vm.resource = AeUser.applications[0].resource_id;
441 vm.resource = AeUser.applications[0].resource_id;
442 }
442 }
443 }
443 }
444 }
444 }
445
445
446 var timespan = $location.search().timespan;
446 var timespan = $location.search().timespan;
447
447
448 if(_.has(vm.timeOptions, timespan)){
448 if(_.has(vm.timeOptions, timespan)){
449 vm.timeSpan = vm.timeOptions[timespan];
449 vm.timeSpan = vm.timeOptions[timespan];
450 }
450 }
451 else{
451 else{
452 vm.timeSpan = vm.timeOptions['1h'];
452 vm.timeSpan = vm.timeOptions['1h'];
453 }
453 }
454
454
455 var graphType = $location.search().graphtype;
455 var graphType = $location.search().graphtype;
456 if(!graphType){
456 if(!graphType){
457 vm.graphType = {selected: 'metrics_graphs'};
457 vm.graphType = {selected: 'metrics_graphs'};
458 }
458 }
459 else{
459 else{
460 vm.graphType = {selected: graphType};
460 vm.graphType = {selected: graphType};
461 }
461 }
462 vm.updateSearchParams();
462 vm.updateSearchParams();
463 };
463 };
464
464
465 vm.updateSearchParams = function () {
465 vm.updateSearchParams = function () {
466 $location.search('resource', vm.resource);
466 $location.search('resource', vm.resource);
467 $location.search('timespan', vm.timeSpan.key);
467 $location.search('timespan', vm.timeSpan.key);
468 $location.search('graphtype', vm.graphType.selected);
468 $location.search('graphtype', vm.graphType.selected);
469 stateHolder.resource = vm.resource;
469 stateHolder.resource = vm.resource;
470 if (vm.resource){
470 if (vm.resource){
471 $cookies.putObject('resource', vm.resource,
471 $cookies.putObject('resource', vm.resource,
472 {expires:new Date(3000, 1, 1)});
472 {expires:new Date(3000, 1, 1)});
473 }
473 }
474 };
474 };
475
475
476 vm.refreshData = function () {
476 vm.refreshData = function () {
477 vm.fetchApdexStats();
477 vm.fetchApdexStats();
478 vm.fetchTrendingReports();
478 vm.fetchTrendingReports();
479 vm.fetchMetrics();
479 vm.fetchMetrics();
480 vm.fetchRequestsBreakdown();
480 vm.fetchRequestsBreakdown();
481 vm.fetchSlowCalls();
481 vm.fetchSlowCalls();
482 }
482 }
483
483
484 vm.changedTimeSpan = function(){
484 vm.changedTimeSpan = function(){
485 vm.startDateFilter = timeSpanToStartDate(vm.timeSpan.key);
485 vm.startDateFilter = timeSpanToStartDate(vm.timeSpan.key);
486 vm.refreshData();
486 vm.refreshData();
487 }
487 }
488
488
489 var intervalId = $interval(function () {
489 var intervalId = $interval(function () {
490 if (_.contains(['30m', "1h"], vm.timeSpan.key)) {
490 if (_.contains(['30m', "1h"], vm.timeSpan.key)) {
491 // don't do anything if window is unfocused
492 if(document.hidden === true){
493 return ;
494 }
491 vm.refreshData();
495 vm.refreshData();
492 }
496 }
493 }, 60000);
497 }, 60000);
494
498
495 $scope.$on('$destroy',function(){
499 $scope.$on('$destroy',function(){
496 $interval.cancel(intervalId);
500 $interval.cancel(intervalId);
497 vm.websocket.close();
501 if (vm.websocket && vm.websocket.readyState == 1){
502 vm.websocket.close();
503 }
498 });
504 });
499
505
500
506
501 vm.fetchApdexStats = function () {
507 vm.fetchApdexStats = function () {
502 vm.loading.apdex = true;
508 vm.loading.apdex = true;
503 vm.apdexStats = applicationsPropertyResource.query({
509 vm.apdexStats = applicationsPropertyResource.query({
504 'key': 'apdex_stats',
510 'key': 'apdex_stats',
505 'resourceId': vm.resource,
511 'resourceId': vm.resource,
506 "start_date": timeSpanToStartDate(vm.timeSpan.key)
512 "start_date": timeSpanToStartDate(vm.timeSpan.key)
507 },
513 },
508 function (data) {
514 function (data) {
509 vm.loading.apdex = false;
515 vm.loading.apdex = false;
510
516
511 vm.exceptions = _.reduce(data, function (memo, row) {
517 vm.exceptions = _.reduce(data, function (memo, row) {
512 return memo + row.errors;
518 return memo + row.errors;
513 }, 0);
519 }, 0);
514 vm.satisfyingRequests = _.reduce(data, function (memo, row) {
520 vm.satisfyingRequests = _.reduce(data, function (memo, row) {
515 return memo + row.satisfying_requests;
521 return memo + row.satisfying_requests;
516 }, 0);
522 }, 0);
517 vm.toleratedRequests = _.reduce(data, function (memo, row) {
523 vm.toleratedRequests = _.reduce(data, function (memo, row) {
518 return memo + row.tolerated_requests;
524 return memo + row.tolerated_requests;
519 }, 0);
525 }, 0);
520 vm.frustratingRequests = _.reduce(data, function (memo, row) {
526 vm.frustratingRequests = _.reduce(data, function (memo, row) {
521 return memo + row.frustrating_requests;
527 return memo + row.frustrating_requests;
522 }, 0);
528 }, 0);
523 if (data.length) {
529 if (data.length) {
524 vm.uptimeStats = data[0].uptime;
530 vm.uptimeStats = data[0].uptime;
525 }
531 }
526
532
527 },
533 },
528 function () {
534 function () {
529 vm.loading.apdex = false;
535 vm.loading.apdex = false;
530 }
536 }
531 );
537 );
532 }
538 }
533
539
534 vm.fetchMetrics = function () {
540 vm.fetchMetrics = function () {
535 vm.loading.series = true;
541 vm.loading.series = true;
536 applicationsPropertyResource.query({
542 applicationsPropertyResource.query({
537 'resourceId': vm.resource,
543 'resourceId': vm.resource,
538 'key': vm.graphType.selected,
544 'key': vm.graphType.selected,
539 "start_date": timeSpanToStartDate(vm.timeSpan.key)
545 "start_date": timeSpanToStartDate(vm.timeSpan.key)
540 }, function (data) {
546 }, function (data) {
541 if (vm.graphType.selected == 'metrics_graphs') {
547 if (vm.graphType.selected == 'metrics_graphs') {
542 vm.metricsChartData = {
548 vm.metricsChartData = {
543 json: data,
549 json: data,
544 xFormat: '%Y-%m-%dT%H:%M:%S',
550 xFormat: '%Y-%m-%dT%H:%M:%S',
545 keys: {
551 keys: {
546 x: 'x',
552 x: 'x',
547 value: ["main", "sql", "nosql", "tmpl", "remote", "custom"]
553 value: ["main", "sql", "nosql", "tmpl", "remote", "custom"]
548 },
554 },
549 names: {
555 names: {
550 main: 'View/Application logic',
556 main: 'View/Application logic',
551 sql: 'Relational database queries',
557 sql: 'Relational database queries',
552 nosql: 'NoSql datastore calls',
558 nosql: 'NoSql datastore calls',
553 tmpl: 'Template rendering',
559 tmpl: 'Template rendering',
554 custom: 'Custom timed calls',
560 custom: 'Custom timed calls',
555 remote: 'Requests to remote resources'
561 remote: 'Requests to remote resources'
556 },
562 },
557 type: 'area',
563 type: 'area',
558 groups: [["main", "sql", "nosql", "remote", "custom", "tmpl"]],
564 groups: [["main", "sql", "nosql", "remote", "custom", "tmpl"]],
559 order: null
565 order: null
560 };
566 };
561 }
567 }
562 else if (vm.graphType.selected == 'report_graphs') {
568 else if (vm.graphType.selected == 'report_graphs') {
563 vm.reportChartData = {
569 vm.reportChartData = {
564 json: data,
570 json: data,
565 xFormat: '%Y-%m-%dT%H:%M:%S',
571 xFormat: '%Y-%m-%dT%H:%M:%S',
566 keys: {
572 keys: {
567 x: 'x',
573 x: 'x',
568 value: ["not_found", "report"]
574 value: ["not_found", "report"]
569 },
575 },
570 names: {
576 names: {
571 report: 'Errors',
577 report: 'Errors',
572 not_found: '404\'s requests'
578 not_found: '404\'s requests'
573 },
579 },
574 type: 'bar'
580 type: 'bar'
575 };
581 };
576 }
582 }
577 else if (vm.graphType.selected == 'slow_report_graphs') {
583 else if (vm.graphType.selected == 'slow_report_graphs') {
578 vm.reportSlowChartData = {
584 vm.reportSlowChartData = {
579 json: data,
585 json: data,
580 xFormat: '%Y-%m-%dT%H:%M:%S',
586 xFormat: '%Y-%m-%dT%H:%M:%S',
581 keys: {
587 keys: {
582 x: 'x',
588 x: 'x',
583 value: ["slow_report"]
589 value: ["slow_report"]
584 },
590 },
585 names: {
591 names: {
586 slow_report: 'Slow reports'
592 slow_report: 'Slow reports'
587 },
593 },
588 type: 'bar'
594 type: 'bar'
589 };
595 };
590 }
596 }
591 else if (vm.graphType.selected == 'response_graphs') {
597 else if (vm.graphType.selected == 'response_graphs') {
592 vm.responseChartData = {
598 vm.responseChartData = {
593 json: data,
599 json: data,
594 xFormat: '%Y-%m-%dT%H:%M:%S',
600 xFormat: '%Y-%m-%dT%H:%M:%S',
595 keys: {
601 keys: {
596 x: 'x',
602 x: 'x',
597 value: ["today", "days_ago_2", "days_ago_7"]
603 value: ["today", "days_ago_2", "days_ago_7"]
598 },
604 },
599 names: {
605 names: {
600 today: 'Today',
606 today: 'Today',
601 "days_ago_2": '2 days ago',
607 "days_ago_2": '2 days ago',
602 "days_ago_7": '7 days ago'
608 "days_ago_7": '7 days ago'
603 }
609 }
604 };
610 };
605 }
611 }
606 else if (vm.graphType.selected == 'requests_graphs') {
612 else if (vm.graphType.selected == 'requests_graphs') {
607 vm.requestsChartData = {
613 vm.requestsChartData = {
608 json: data,
614 json: data,
609 xFormat: '%Y-%m-%dT%H:%M:%S',
615 xFormat: '%Y-%m-%dT%H:%M:%S',
610 keys: {
616 keys: {
611 x: 'x',
617 x: 'x',
612 value: ["requests"]
618 value: ["requests"]
613 },
619 },
614 names: {
620 names: {
615 requests: 'Requests/s'
621 requests: 'Requests/s'
616 }
622 }
617 };
623 };
618 }
624 }
619 vm.loading.series = false;
625 vm.loading.series = false;
620 }, function(){
626 }, function(){
621 vm.loading.series = false;
627 vm.loading.series = false;
622 });
628 });
623 }
629 }
624
630
625 vm.fetchSlowCalls = function () {
631 vm.fetchSlowCalls = function () {
626 vm.loading.slowCalls = true;
632 vm.loading.slowCalls = true;
627 applicationsPropertyResource.query({
633 applicationsPropertyResource.query({
628 'resourceId': vm.resource,
634 'resourceId': vm.resource,
629 "start_date": timeSpanToStartDate(vm.timeSpan.key),
635 "start_date": timeSpanToStartDate(vm.timeSpan.key),
630 'key': 'slow_calls'
636 'key': 'slow_calls'
631 }, function (data) {
637 }, function (data) {
632 vm.slowCalls = data;
638 vm.slowCalls = data;
633 vm.loading.slowCalls = false;
639 vm.loading.slowCalls = false;
634 }, function () {
640 }, function () {
635 vm.loading.slowCalls = false;
641 vm.loading.slowCalls = false;
636 });
642 });
637 }
643 }
638
644
639 vm.fetchRequestsBreakdown = function () {
645 vm.fetchRequestsBreakdown = function () {
640 vm.loading.requestsBreakdown = true;
646 vm.loading.requestsBreakdown = true;
641 applicationsPropertyResource.query({
647 applicationsPropertyResource.query({
642 'resourceId': vm.resource,
648 'resourceId': vm.resource,
643 "start_date": timeSpanToStartDate(vm.timeSpan.key),
649 "start_date": timeSpanToStartDate(vm.timeSpan.key),
644 'key': 'requests_breakdown'
650 'key': 'requests_breakdown'
645 }, function (data) {
651 }, function (data) {
646 vm.requestsBreakdown = data;
652 vm.requestsBreakdown = data;
647 vm.loading.requestsBreakdown = false;
653 vm.loading.requestsBreakdown = false;
648 }, function () {
654 }, function () {
649 vm.loading.requestsBreakdown = false;
655 vm.loading.requestsBreakdown = false;
650 });
656 });
651 }
657 }
652
658
653 vm.fetchTrendingReports = function () {
659 vm.fetchTrendingReports = function () {
654
660
655 if (vm.graphType.selected == 'slow_report_graphs') {
661 if (vm.graphType.selected == 'slow_report_graphs') {
656 var report_type = 'slow';
662 var report_type = 'slow';
657 }
663 }
658 else {
664 else {
659 var report_type = 'error';
665 var report_type = 'error';
660 }
666 }
661
667
662 vm.loading.reports = true;
668 vm.loading.reports = true;
663 vm.trendingReports = applicationsPropertyResource.query({
669 vm.trendingReports = applicationsPropertyResource.query({
664 'key': 'trending_reports',
670 'key': 'trending_reports',
665 'resourceId': vm.resource,
671 'resourceId': vm.resource,
666 "start_date": timeSpanToStartDate(vm.timeSpan.key),
672 "start_date": timeSpanToStartDate(vm.timeSpan.key),
667 "report_type": report_type
673 "report_type": report_type
668 },
674 },
669 function () {
675 function () {
670 vm.loading.reports = false;
676 vm.loading.reports = false;
671 },
677 },
672 function () {
678 function () {
673 vm.loading.reports = false;
679 vm.loading.reports = false;
674 }
680 }
675 )
681 )
676 ;
682 ;
677 }
683 }
678
684
679 if (AeUser.applications.length){
685 if (AeUser.applications.length){
680 vm.show_dashboard = true;
686 vm.show_dashboard = true;
681 vm.determineStartState();
687 vm.determineStartState();
682 vm.refreshData();
688 vm.refreshData();
683 }
689 }
684
690
685 $scope.$on('$locationChangeSuccess', function () {
691 $scope.$on('$locationChangeSuccess', function () {
686 console.log('$locationChangeSuccess IndexDashboardController');
692 console.log('$locationChangeSuccess IndexDashboardController');
687 if (vm.loading.series === false) {
693 if (vm.loading.series === false) {
688 vm.determineStartState();
694 vm.determineStartState();
689 vm.refreshData();
695 vm.refreshData();
690 }
696 }
691 });
697 });
692
698
693
699
694 }
700 }
General Comments 0
You need to be logged in to leave comments. Login now