Add additional stats items #13

Merged
fred.boniface merged 3 commits from devel into main 2023-05-07 21:22:09 +01:00
3 changed files with 42 additions and 13 deletions

View File

@ -1,6 +1,6 @@
const version = {
api: ['/api/v1/',],
app: '2.0.0'
app: '2.0.1'
};
module.exports = version;

View File

@ -73,11 +73,21 @@ async function delRegReq(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 = {
query,
increment, // Probqbly doesn't need exporting? - It does, ldbServices needs to increment when the API is hit!
addUser,
userAtime,
addRegReq,
delRegReq
delRegReq,
colCount
};

View File

@ -1,21 +1,40 @@
/* global process */
const log = require('../utils/log.utils'); // Log Helper
const db = require('../services/dbAccess.services');
const os = require('os');
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(){
log.out('statsServices.hits: Statistics Requested', 'info');
var dat = db.query('meta', {target: 'counters'});
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;
const out = await buildJson();
log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`, 'info');
return out;
}