mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-15 02:50:10 +01:00
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
const { SystemSettings } = require("../models/systemSettings");
|
|
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
|
|
function getGitVersion() {
|
|
if (process.env.ANYTHING_LLM_RUNTIME === "docker") return "--";
|
|
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,
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
utilEndpoints,
|
|
getGitVersion,
|
|
};
|