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