2016-09-19 21:33:46 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const express = require('express')
|
|
|
|
|
2016-10-21 12:16:28 +02:00
|
|
|
const constants = require('../../initializers/constants')
|
2016-12-11 21:50:51 +01:00
|
|
|
const db = require('../../initializers/database')
|
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) {
|
2016-12-11 21:50:51 +01:00
|
|
|
db.Request.countTotalRequests(function (err, totalRequests) {
|
2016-09-19 21:33:46 +02:00
|
|
|
if (err) return next(err)
|
|
|
|
|
|
|
|
return res.json({
|
2016-12-11 21:50:51 +01:00
|
|
|
totalRequests: totalRequests,
|
2016-10-01 15:43:42 +02:00
|
|
|
maxRequestsInParallel: constants.REQUESTS_IN_PARALLEL,
|
2016-12-11 21:50:51 +01:00
|
|
|
remainingMilliSeconds: db.Request.remainingMilliSeconds(),
|
2016-09-23 17:09:38 +02:00
|
|
|
milliSecondsInterval: constants.REQUESTS_INTERVAL
|
2016-09-19 21:33:46 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|