From 99fdec464802e5d720fe08ead06b63368b115baf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Feb 2017 21:56:55 +0100 Subject: Fix request schedulers stats --- .../request-stats/request-stats.component.html | 50 +++++++++--------- .../request-stats/request-stats.component.scss | 4 ++ .../request-stats/request-stats.component.ts | 60 ++++++++++++++++------ .../app/+admin/requests/shared/request.service.ts | 14 ++++- client/src/app/shared/shared.module.ts | 3 ++ 5 files changed, 89 insertions(+), 42 deletions(-) (limited to 'client') diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.html b/client/src/app/+admin/requests/request-stats/request-stats.component.html index 9dbed1739..ca531258c 100644 --- a/client/src/app/+admin/requests/request-stats/request-stats.component.html +++ b/client/src/app/+admin/requests/request-stats/request-stats.component.html @@ -1,33 +1,37 @@

Requests stats

-
-
-
- Remaining requests: - {{ stats.totalRequests }} -
+
+
+

{{ statsTitles[requestSchedulerName] }}

-
- Interval seconds between requests: - {{ stats.secondsInterval }} -
+
+
+ Remaining requests: + {{ stats[requestSchedulerName].totalRequests }} +
-
- Remaining time before the scheduled request: - {{ stats.remainingSeconds }} -
-
+
+ Interval seconds between requests: + {{ stats[requestSchedulerName].secondsInterval }} +
-
-
- Maximum number of different pods for a scheduled request: - {{ stats.requestsLimitPods }} +
+ Remaining time before the scheduled request: + {{ stats[requestSchedulerName].remainingSeconds }} +
-
- Maximum number of requests per pod for a scheduled request: - {{ stats.requestsLimitPerPod }} +
+
+ Maximum number of different pods for a scheduled request: + {{ stats[requestSchedulerName].requestsLimitPods }} +
+ +
+ Maximum number of requests per pod for a scheduled request: + {{ stats[requestSchedulerName].requestsLimitPerPod }} +
-
+
diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.scss b/client/src/app/+admin/requests/request-stats/request-stats.component.scss index 9c68fba99..c9f724604 100644 --- a/client/src/app/+admin/requests/request-stats/request-stats.component.scss +++ b/client/src/app/+admin/requests/request-stats/request-stats.component.scss @@ -1,3 +1,7 @@ +.block { + margin-bottom: 40px; +} + .label-description { display: inline-block; font-weight: bold; diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.ts b/client/src/app/+admin/requests/request-stats/request-stats.component.ts index 18855a5f8..85dd7e492 100644 --- a/client/src/app/+admin/requests/request-stats/request-stats.component.ts +++ b/client/src/app/+admin/requests/request-stats/request-stats.component.ts @@ -10,10 +10,30 @@ import { RequestService, RequestStats } from '../shared'; styleUrls: [ './request-stats.component.scss' ] }) export class RequestStatsComponent implements OnInit, OnDestroy { - stats: RequestStats = null; + statsTitles = { + requestScheduler: 'Basic request scheduler', + requestVideoEventScheduler: 'Video events request scheduler', + requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler' + }; + + stats: { [ id: string ]: RequestStats } = { + requestScheduler: null, + requestVideoEventScheduler: null, + requestVideoQaduScheduler: null + }; + + private intervals: { [ id: string ]: number } = { + requestScheduler: null, + requestVideoEventScheduler: null, + requestVideoQaduScheduler: null + }; + + private timeouts: { [ id: string ]: number } = { + requestScheduler: null, + requestVideoEventScheduler: null, + requestVideoQaduScheduler: null + }; - private interval: number = null; - private timeout: number = null; constructor( private notificationsService: NotificationsService, @@ -22,17 +42,19 @@ export class RequestStatsComponent implements OnInit, OnDestroy { ngOnInit() { this.getStats(); - this.runInterval(); + this.runIntervals(); } ngOnDestroy() { - if (this.interval !== null) { - window.clearInterval(this.interval); - } + Object.keys(this.stats).forEach(requestSchedulerName => { + if (this.intervals[requestSchedulerName] !== null) { + window.clearInterval(this.intervals[requestSchedulerName]); + } - if (this.timeout !== null) { - window.clearTimeout(this.timeout); - } + if (this.timeouts[requestSchedulerName] !== null) { + window.clearTimeout(this.timeouts[requestSchedulerName]); + } + }); } getStats() { @@ -43,14 +65,18 @@ export class RequestStatsComponent implements OnInit, OnDestroy { ); } - private runInterval() { - this.interval = window.setInterval(() => { - this.stats.remainingMilliSeconds -= 1000; + private runIntervals() { + Object.keys(this.intervals).forEach(requestSchedulerName => { + this.intervals[requestSchedulerName] = window.setInterval(() => { + const stats = this.stats[requestSchedulerName]; - if (this.stats.remainingMilliSeconds <= 0) { - this.timeout = window.setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100); - } - }, 1000); + stats.remainingMilliSeconds -= 1000; + + if (stats.remainingMilliSeconds <= 0) { + this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100); + } + }, 1000); + }); } diff --git a/client/src/app/+admin/requests/shared/request.service.ts b/client/src/app/+admin/requests/shared/request.service.ts index 55b28bcfc..915d192a6 100644 --- a/client/src/app/+admin/requests/shared/request.service.ts +++ b/client/src/app/+admin/requests/shared/request.service.ts @@ -15,10 +15,20 @@ export class RequestService { private restExtractor: RestExtractor ) {} - getStats(): Observable { + getStats(): Observable<{ [ id: string ]: RequestStats }> { return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats') .map(this.restExtractor.extractDataGet) - .map((data) => new RequestStats(data)) + .map(this.buildRequestObjects) .catch((res) => this.restExtractor.handleError(res)); } + + private buildRequestObjects(data: any) { + const requestSchedulers = {}; + + Object.keys(data).forEach(requestSchedulerName => { + requestSchedulers[requestSchedulerName] = new RequestStats(data[requestSchedulerName]); + }); + + return requestSchedulers; + } } diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index 99893c8b1..0f57ef078 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts @@ -5,6 +5,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; +import { KeysPipe } from 'angular-pipes/src/object/keys.pipe'; import { DropdownModule } from 'ng2-bootstrap/dropdown'; import { ProgressbarModule } from 'ng2-bootstrap/progressbar'; import { PaginationModule } from 'ng2-bootstrap/pagination'; @@ -36,6 +37,7 @@ import { VideoAbuseService } from './video-abuse'; declarations: [ BytesPipe, + KeysPipe, SearchComponent ], @@ -53,6 +55,7 @@ import { VideoAbuseService } from './video-abuse'; ProgressbarModule, Ng2SmartTableModule, BytesPipe, + KeysPipe, SearchComponent ], -- cgit v1.2.3