mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-08-19 20:00:11 +02:00
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
const { SystemSettings } = require("../models/systemSettings");
|
|
|
|
function getGitVersion() {
|
|
try {
|
|
return require("child_process")
|
|
.execSync("git rev-parse HEAD")
|
|
.toString()
|
|
.trim();
|
|
} catch (e) {
|
|
console.error("getGitVersion", e.message);
|
|
return "--";
|
|
}
|
|
}
|
|
|
|
function byteToGigaByte(n) {
|
|
return n / Math.pow(10, 9);
|
|
}
|
|
|
|
async function getDiskStorage() {
|
|
try {
|
|
const checkDiskSpace = require("check-disk-space").default;
|
|
const { free, size } = await checkDiskSpace("/");
|
|
return {
|
|
current: Math.floor(byteToGigaByte(free)),
|
|
capacity: Math.floor(byteToGigaByte(size)),
|
|
};
|
|
} catch {
|
|
return {
|
|
current: null,
|
|
capacity: null,
|
|
};
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = { utilEndpoints, getGitVersion };
|