Add /misc/server/statistics route
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
/* global process */
|
||||
const log = require('../utils/log.utils'); // Log Helper
|
||||
const db = require('../services/dbAccess.services');
|
||||
const os = require('os');
|
||||
@@ -54,7 +53,84 @@ async function versions() {
|
||||
return data;
|
||||
}
|
||||
|
||||
async function statistics() {
|
||||
log.out('statsServices.statistics: Fetching statistics', 'info');
|
||||
|
||||
const countersPromise = db.query('meta', { target: 'counters' });
|
||||
const timetablePromise = db.query('meta', { target: 'timetable' });
|
||||
const pisPromise = db.query('meta', { target: 'pis' });
|
||||
const corpusPromise = db.query('meta', { target: 'corpus' });
|
||||
const reasonCodesPromise = db.query('meta', { target: 'reasonCodes' });
|
||||
|
||||
const lengthUsersPromise = db.colCount('users');
|
||||
const lengthRegistrationsPromise = db.colCount('registrations');
|
||||
const lengthCorpusPromise = db.colCount('corpus');
|
||||
const lengthStationsPromise = db.colCount('stations');
|
||||
const lengthPisPromise = db.colCount('pis');
|
||||
const lengthTimetablePromise = db.colCount('timetable');
|
||||
const lengthReasonCodesPromise = db.colCount('reasonCodes');
|
||||
|
||||
const [
|
||||
counters,
|
||||
timetable,
|
||||
pis,
|
||||
corpus,
|
||||
reasonCodes,
|
||||
lengthUsers,
|
||||
lengthRegistrations,
|
||||
lengthCorpus,
|
||||
lengthStations,
|
||||
lengthPis,
|
||||
lengthTimetable,
|
||||
lengthReasonCodes
|
||||
] = await Promise.all([
|
||||
countersPromise,
|
||||
timetablePromise,
|
||||
pisPromise,
|
||||
corpusPromise,
|
||||
reasonCodesPromise,
|
||||
lengthUsersPromise,
|
||||
lengthRegistrationsPromise,
|
||||
lengthCorpusPromise,
|
||||
lengthStationsPromise,
|
||||
lengthPisPromise,
|
||||
lengthTimetablePromise,
|
||||
lengthReasonCodesPromise
|
||||
]);
|
||||
|
||||
return {
|
||||
hostname: os.hostname() || 'Unknown',
|
||||
runtimeMode: process.env.NODE_ENV || 'Unknown',
|
||||
updateTimes: {
|
||||
timetable: timetable[0]['updated'],
|
||||
pis: pis[0]['updated'],
|
||||
corpus: corpus[0]['updated'],
|
||||
reasonCodes: reasonCodes[0]['updated']
|
||||
},
|
||||
requestCounts: {
|
||||
ldbws_api: counters[0]['ldbws'] || 0,
|
||||
lsbsvws_api: counters[0]['ldbsvws'] || 0,
|
||||
corpus_api: counters[0]['corpus_api'] || 0,
|
||||
timetable_db: counters[0]['timetable'] || 0,
|
||||
pis_db: counters[0]['pis'] || 0,
|
||||
corpus_db: counters[0]['corpus'] || 0,
|
||||
stations_db: counters[0]['stations'] || 0
|
||||
},
|
||||
dbLengths: {
|
||||
users: lengthUsers,
|
||||
registrations: lengthRegistrations,
|
||||
corpus: lengthCorpus,
|
||||
stations: lengthStations,
|
||||
pis: lengthPis,
|
||||
timetable: lengthTimetable,
|
||||
reasonCodes: lengthReasonCodes
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
hits,
|
||||
versions
|
||||
versions,
|
||||
statistics
|
||||
};
|
||||
Reference in New Issue
Block a user