Compare commits

..

No commits in common. "c4646bc6549af913efe662ab958168c8a01bafe8" and "a561357fbece6393ea64bae11e34e99bc16747c0" have entirely different histories.

3 changed files with 29 additions and 9 deletions

View File

@ -5,7 +5,7 @@ interface versions {
const version: versions = {
api: ["/api/v2"],
app: "2025.03.1",
app: "2024.11.2",
};
module.exports = version;

View File

@ -10,7 +10,6 @@ import { queryAggregate } from "./dbAccess.services";
import {
getPartialEndTiplocMatchPipeline,
getFullTiplocMatchPipeline,
getPartialStartTiplocMatchPipeline,
} from "../utils/pis.utils";
import { Document } from "mongodb";

View File

@ -8,6 +8,8 @@ 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");
@ -17,8 +19,12 @@ async function buildJson() {
// Insert data
json.mode = process.env.NODE_ENV;
json.verBkend = vers.app;
json.verApi = vers.api;
json.host = 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;
@ -36,9 +42,11 @@ async function hits() {
async function getVersions() {
logger.debug("statsServices.getVersions: Fetching versions");
const dbMan = await db.query("versions", { target: "dbmanager" });
const mqClt = await db.query("versions", { target: "timetable-mgr" });
const data = {
backend: vers.app,
"db-manager": dbMan[0]?.["version"] || "",
"mq-client": mqClt[0]?.["version"] || "",
};
return data;
@ -47,10 +55,11 @@ async function getVersions() {
async function statistics() {
logger.debug("statsServices.statistics: Fetching statistics");
const countersPromise = db.query("meta", { target: "counters" });
const timetablePromise = db.query("meta", { type: "CifMetadata" });
const pisPromise = db.query("meta", { target: "PisMetadata" });
const pisPromise = db.query("meta", { target: "pis" });
const corpusPromise = db.query("meta", { target: "corpus" });
const stationsPromise = db.query("meta", {type: "StationsMetadata"});
const reasonCodesPromise = db.query("meta", { target: "reasonCodes" });
const lengthUsersPromise = db.colCount("users");
const lengthRegistrationsPromise = db.colCount("registrations");
@ -61,6 +70,7 @@ async function statistics() {
const lengthReasonCodesPromise = db.colCount("reasonCodes");
const [
counters,
timetable,
pis,
corpus,
@ -71,11 +81,13 @@ async function statistics() {
lengthStations,
lengthPis,
lengthTimetable,
stations,
lengthReasonCodes,
] = await Promise.all([
countersPromise,
timetablePromise,
pisPromise,
corpusPromise,
reasonCodesPromise,
lengthUsersPromise,
lengthRegistrationsPromise,
lengthCorpusPromise,
@ -83,7 +95,6 @@ async function statistics() {
lengthPisPromise,
lengthTimetablePromise,
lengthReasonCodesPromise,
stationsPromise,
]);
return {
@ -92,9 +103,18 @@ async function statistics() {
reset: counters[0]["since"],
updateTimes: {
timetable: (timetable[0]["lastUpdate"]),
pis: pis[0]["lastUpdate"],
corpus: corpus[0]["updated_time"],
stations: stations[0]["lastUpdate"],
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,
@ -103,6 +123,7 @@ async function statistics() {
stations: lengthStations,
pis: lengthPis,
timetable: lengthTimetable,
reasonCodes: lengthReasonCodes,
},
};
}