Add additional stats items #13

Merged
fred.boniface merged 3 commits from devel into main 2023-05-07 21:22:09 +01:00
2 changed files with 40 additions and 12 deletions
Showing only changes of commit 99c7842c2a - Show all commits

View File

@ -73,11 +73,21 @@ async function delRegReq(uuid) {
col.deleteOne({uuid: uuid}); col.deleteOne({uuid: uuid});
} }
async function colCount(collection) {
log.out(`dbAccess.colCount: Counting entries in collection: ${collection}`);
await client.connect();
let col = db.collection(collection);
let count = col.countDocuments();
log.out(`dbAccess.colCount: Collection: ${collection} contains ${count} documents`);
return await count;
}
module.exports = { module.exports = {
query, query,
increment, // Probqbly doesn't need exporting? - It does, ldbServices needs to increment when the API is hit! increment, // Probqbly doesn't need exporting? - It does, ldbServices needs to increment when the API is hit!
addUser, addUser,
userAtime, userAtime,
addRegReq, addRegReq,
delRegReq delRegReq,
colCount
}; };

View File

@ -3,19 +3,37 @@ const db = require('../services/dbAccess.services');
const os = require('os'); const os = require('os');
const vers = require('../configs/version.configs'); const vers = require('../configs/version.configs');
async function buildJson() {
let json = {};
json.count = {};
// Async call all db queries
const counters = db.query('meta', {target: 'counters'});
const versions = db.query('meta', {target: 'versions'});
const userCount = db.colCount('users');
const regCount = db.colCount('registrations');
const pisCount = db.colCount('pis');
const corpusCount = db.colCount('corpus');
const stationsCount = db.colCount('stations');
// Insert data
json.mode = process.env.NODE_ENV;
json.verBkend = vers.app;
json.verApi = vers.api;
json.hostname = os.hostname();
// Await and insert async calls
json.dat = await counters;
json.ver = await versions;
json.count.users = await userCount;
json.count.reg = await regCount;
json.count.pis = await pisCount;
json.count.corpus = await corpusCount;
json.count.stations = await stationsCount;
return json;
}
async function hits(){ async function hits(){
log.out('statsServices.hits: Statistics Requested', 'info'); log.out('statsServices.hits: Statistics Requested', 'info');
var dat = db.query('meta', {target: 'counters'}); const out = await buildJson();
var ver = db.query('meta', {target: 'versions'});
log.out('statsServices.hits: fetched server meta', 'info');
let out = {};
out.host = os.hostname();
// eslint-disable-next-line no-undef
out.mode = process.env.NODE_ENV;
out.verBkend = vers.app;
out.verApi = vers.api;
out.dat = await dat;
out.ver = await ver;
log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`, 'info'); log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`, 'info');
return out; return out;
} }