2023-08-10 22:23:23 +02:00
|
|
|
const { SystemSettings } = require("../models/systemSettings");
|
|
|
|
|
2024-01-22 23:14:01 +01:00
|
|
|
function utilEndpoints(app) {
|
|
|
|
if (!app) return;
|
|
|
|
|
|
|
|
app.get("/utils/metrics", async (_, response) => {
|
|
|
|
try {
|
|
|
|
const metrics = {
|
|
|
|
online: true,
|
|
|
|
version: getGitVersion(),
|
|
|
|
mode: (await SystemSettings.isMultiUserMode())
|
|
|
|
? "multi-user"
|
|
|
|
: "single-user",
|
|
|
|
vectorDB: process.env.VECTOR_DB || "lancedb",
|
|
|
|
storage: await getDiskStorage(),
|
|
|
|
};
|
|
|
|
response.status(200).json(metrics);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.sendStatus(500).end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-10 22:23:23 +02:00
|
|
|
function getGitVersion() {
|
2023-08-15 20:36:07 +02:00
|
|
|
try {
|
|
|
|
return require("child_process")
|
|
|
|
.execSync("git rev-parse HEAD")
|
|
|
|
.toString()
|
|
|
|
.trim();
|
|
|
|
} catch (e) {
|
|
|
|
console.error("getGitVersion", e.message);
|
|
|
|
return "--";
|
|
|
|
}
|
2023-08-10 22:23:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function byteToGigaByte(n) {
|
|
|
|
return n / Math.pow(10, 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getDiskStorage() {
|
|
|
|
try {
|
|
|
|
const checkDiskSpace = require("check-disk-space").default;
|
2023-08-10 22:50:17 +02:00
|
|
|
const { free, size } = await checkDiskSpace("/");
|
2023-08-10 22:23:23 +02:00
|
|
|
return {
|
|
|
|
current: Math.floor(byteToGigaByte(free)),
|
|
|
|
capacity: Math.floor(byteToGigaByte(size)),
|
|
|
|
};
|
|
|
|
} catch {
|
|
|
|
return {
|
|
|
|
current: null,
|
|
|
|
capacity: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-19 02:59:51 +01:00
|
|
|
module.exports = {
|
|
|
|
utilEndpoints,
|
|
|
|
getGitVersion,
|
|
|
|
};
|