<h3>Requests stats</h3>
-<div *ngIf="stats !== null">
- <div class="requests-general">
- <div>
- <span class="label-description">Remaining requests:</span>
- {{ stats.totalRequests }}
- </div>
+<div *ngFor="let requestSchedulerName of statsTitles | keys">
+ <div class="block" *ngIf="stats[requestSchedulerName] !== null">
+ <h4>{{ statsTitles[requestSchedulerName] }}</h4>
- <div>
- <span class="label-description">Interval seconds between requests:</span>
- {{ stats.secondsInterval }}
- </div>
+ <div class="requests-general">
+ <div>
+ <span class="label-description">Remaining requests:</span>
+ {{ stats[requestSchedulerName].totalRequests }}
+ </div>
- <div>
- <span class="label-description">Remaining time before the scheduled request:</span>
- {{ stats.remainingSeconds }}
- </div>
- </div>
+ <div>
+ <span class="label-description">Interval seconds between requests:</span>
+ {{ stats[requestSchedulerName].secondsInterval }}
+ </div>
- <div class="requests-limit">
- <div>
- <span class="label-description">Maximum number of different pods for a scheduled request:</span>
- {{ stats.requestsLimitPods }}
+ <div>
+ <span class="label-description">Remaining time before the scheduled request:</span>
+ {{ stats[requestSchedulerName].remainingSeconds }}
+ </div>
</div>
- <div>
- <span class="label-description">Maximum number of requests per pod for a scheduled request:</span>
- {{ stats.requestsLimitPerPod }}
+ <div class="requests-limit">
+ <div>
+ <span class="label-description">Maximum number of different pods for a scheduled request:</span>
+ {{ stats[requestSchedulerName].requestsLimitPods }}
+ </div>
+
+ <div>
+ <span class="label-description">Maximum number of requests per pod for a scheduled request:</span>
+ {{ stats[requestSchedulerName].requestsLimitPerPod }}
+ </div>
</div>
- </div>
+ </div>
</div>
+.block {
+ margin-bottom: 40px;
+}
+
.label-description {
display: inline-block;
font-weight: bold;
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,
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() {
);
}
- 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);
+ });
}
private restExtractor: RestExtractor
) {}
- getStats(): Observable<RequestStats> {
+ 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;
+ }
}
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';
declarations: [
BytesPipe,
+ KeysPipe,
SearchComponent
],
ProgressbarModule,
Ng2SmartTableModule,
BytesPipe,
+ KeysPipe,
SearchComponent
],
'use strict'
const express = require('express')
+const parallel = require('async/parallel')
const constants = require('../../initializers/constants')
-const db = require('../../initializers/database')
+const friends = require('../../lib/friends')
const middlewares = require('../../middlewares')
const admin = middlewares.admin
const oAuth = middlewares.oauth
// ---------------------------------------------------------------------------
function getStatsRequests (req, res, next) {
- db.Request.countTotalRequests(function (err, totalRequests) {
+ parallel({
+ requestScheduler: buildRequestSchedulerFunction(friends.getRequestScheduler()),
+ requestVideoQaduScheduler: buildRequestSchedulerFunction(friends.getRequestVideoQaduScheduler()),
+ requestVideoEventScheduler: buildRequestSchedulerFunction(friends.getRequestVideoEventScheduler())
+ }, function (err, result) {
if (err) return next(err)
- return res.json({
- totalRequests: totalRequests,
- requestsLimitPods: constants.REQUESTS_LIMIT_PODS,
- requestsLimitPerPod: constants.REQUESTS_LIMIT_PER_POD,
- remainingMilliSeconds: db.Request.remainingMilliSeconds(),
- milliSecondsInterval: constants.REQUESTS_INTERVAL
- })
+ return res.json(result)
})
}
+
+// ---------------------------------------------------------------------------
+
+function buildRequestSchedulerFunction (requestScheduler) {
+ return function (callback) {
+ requestScheduler.remainingRequestsCount(function (err, count) {
+ if (err) return callback(err)
+
+ const result = {
+ totalRequests: count,
+ requestsLimitPods: requestScheduler.limitPods,
+ requestsLimitPerPod: requestScheduler.limitPerPod,
+ remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
+ milliSecondsInterval: requestScheduler.requestInterval
+ }
+
+ return callback(null, result)
+ })
+ }
+}
constructor (options) {
this.lastRequestTimestamp = 0
this.timer = null
+ this.requestInterval = constants.REQUESTS_INTERVAL
}
activate () {
this.timer = setInterval(() => {
this.lastRequestTimestamp = Date.now()
this.makeRequests()
- }, constants.REQUESTS_INTERVAL)
+ }, this.requestInterval)
}
deactivate () {
return constants.REQUESTS_INTERVAL - (Date.now() - this.lastRequestTimestamp)
}
+ remainingRequestsCount (callback) {
+ return this.getRequestModel().countTotalRequests(callback)
+ }
+
// ---------------------------------------------------------------------------
// Make a requests to friends of a certain type
const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
const requestScheduler = new RequestScheduler()
-const requestSchedulerVideoQadu = new RequestVideoQaduScheduler()
-const requestSchedulerVideoEvent = new RequestVideoEventScheduler()
+const requestVideoQaduScheduler = new RequestVideoQaduScheduler()
+const requestVideoEventScheduler = new RequestVideoEventScheduler()
const friends = {
activate,
makeFriends,
quitFriends,
removeVideoToFriends,
- sendOwnedVideosToPod
+ sendOwnedVideosToPod,
+ getRequestScheduler,
+ getRequestVideoQaduScheduler,
+ getRequestVideoEventScheduler
}
function activate () {
requestScheduler.activate()
- requestSchedulerVideoQadu.activate()
- requestSchedulerVideoEvent.activate()
+ requestVideoQaduScheduler.activate()
+ requestVideoEventScheduler.activate()
}
function addVideoToFriends (videoData, transaction, callback) {
},
function flushVideoQaduRequests (callbackAsync) {
- requestSchedulerVideoQadu.flush(err => callbackAsync(err))
+ requestVideoQaduScheduler.flush(err => callbackAsync(err))
},
function getPodsList (callbackAsync) {
})
}
+function getRequestScheduler () {
+ return requestScheduler
+}
+
+function getRequestVideoQaduScheduler () {
+ return requestVideoQaduScheduler
+}
+
+function getRequestVideoEventScheduler () {
+ return requestVideoEventScheduler
+}
+
// ---------------------------------------------------------------------------
module.exports = friends
function createVideoQaduRequest (options, callback) {
if (!callback) callback = utils.createEmptyCallback()
- requestSchedulerVideoQadu.createRequest(options, callback)
+ requestVideoQaduScheduler.createRequest(options, callback)
}
function createVideoEventRequest (options, callback) {
if (!callback) callback = utils.createEmptyCallback()
- requestSchedulerVideoEvent.createRequest(options, callback)
+ requestVideoEventScheduler.createRequest(options, callback)
}
function isMe (host) {