2016-09-19 21:33:46 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const express = require('express')
|
2017-02-27 21:56:55 +01:00
|
|
|
const parallel = require('async/parallel')
|
2016-09-19 21:33:46 +02:00
|
|
|
|
2017-02-27 21:56:55 +01:00
|
|
|
const friends = require('../../lib/friends')
|
2016-10-21 12:16:28 +02:00
|
|
|
const middlewares = require('../../middlewares')
|
2016-09-19 21:33:46 +02:00
|
|
|
const admin = middlewares.admin
|
|
|
|
const oAuth = middlewares.oauth
|
|
|
|
|
|
|
|
const router = express.Router()
|
|
|
|
|
|
|
|
router.get('/stats',
|
|
|
|
oAuth.authenticate,
|
|
|
|
admin.ensureIsAdmin,
|
|
|
|
getStatsRequests
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
module.exports = router
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function getStatsRequests (req, res, next) {
|
2017-02-27 21:56:55 +01:00
|
|
|
parallel({
|
|
|
|
requestScheduler: buildRequestSchedulerFunction(friends.getRequestScheduler()),
|
|
|
|
requestVideoQaduScheduler: buildRequestSchedulerFunction(friends.getRequestVideoQaduScheduler()),
|
|
|
|
requestVideoEventScheduler: buildRequestSchedulerFunction(friends.getRequestVideoEventScheduler())
|
|
|
|
}, function (err, result) {
|
2016-09-19 21:33:46 +02:00
|
|
|
if (err) return next(err)
|
|
|
|
|
2017-02-27 21:56:55 +01:00
|
|
|
return res.json(result)
|
2016-09-19 21:33:46 +02:00
|
|
|
})
|
|
|
|
}
|
2017-02-27 21:56:55 +01:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|