diff --git a/packages/backend/src/daemons/server-stats.ts b/packages/backend/src/daemons/server-stats.ts index b0bf1288f..c7aaea035 100644 --- a/packages/backend/src/daemons/server-stats.ts +++ b/packages/backend/src/daemons/server-stats.ts @@ -1,6 +1,7 @@ import si from "systeminformation"; import Xev from "xev"; import * as osUtils from "os-utils"; +import meilisearch from "../db/meilisearch"; const ev = new Xev(); @@ -24,6 +25,7 @@ export default function () { const memStats = await mem(); const netStats = await net(); const fsStats = await fs(); + const meilisearchStats = await meilisearchStatus(); const stats = { cpu: roundCpu(cpu), @@ -39,6 +41,7 @@ export default function () { r: round(Math.max(0, fsStats.rIO_sec ?? 0)), w: round(Math.max(0, fsStats.wIO_sec ?? 0)), }, + meilisearch: meilisearchStats }; ev.emit("serverStats", stats); log.unshift(stats); @@ -77,3 +80,11 @@ async function fs() { const data = await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 })); return data || { rIO_sec: 0, wIO_sec: 0 }; } + +async function meilisearchStatus() { + if (meilisearch) { + return meilisearch.serverStats(); + } else { + return null; + } +} diff --git a/packages/backend/src/db/meilisearch.ts b/packages/backend/src/db/meilisearch.ts index f404b4721..f3561b807 100644 --- a/packages/backend/src/db/meilisearch.ts +++ b/packages/backend/src/db/meilisearch.ts @@ -1,4 +1,4 @@ -import { MeiliSearch } from 'meilisearch'; +import {Health, MeiliSearch, Stats } from 'meilisearch'; import { dbLogger } from "./logger.js"; import config from "@/config/index.js"; @@ -16,7 +16,7 @@ const host = hasConfig ? config.meilisearch.host ?? "localhost" : ""; const port = hasConfig ? config.meilisearch.port ?? 7700 : 0; const auth = hasConfig ? config.meilisearch.apiKey ?? "" : ""; -const client = new MeiliSearch({ +const client : MeiliSearch = new MeiliSearch({ host: `http://${host}:${port}`, apiKey: auth, }) @@ -58,6 +58,16 @@ export default hasConfig ? { userHost: note.userHost, channelId: note.channelId, } - ]) + ]); }, + serverStats: async () => { + let health : Health = await client.health(); + let stats: Stats = await client.getStats(); + + return { + health: health.status, + size: stats.databaseSize, + indexed_count: stats.indexes["posts"].numberOfDocuments + } + } } : null; diff --git a/packages/backend/src/server/api/endpoints/server-info.ts b/packages/backend/src/server/api/endpoints/server-info.ts index 1ce27e262..4b2a4078a 100644 --- a/packages/backend/src/server/api/endpoints/server-info.ts +++ b/packages/backend/src/server/api/endpoints/server-info.ts @@ -1,6 +1,7 @@ import * as os from "node:os"; import si from "systeminformation"; import define from "../define.js"; +import meilisearch from "../../../db/meilisearch"; export const meta = { requireCredential: false, @@ -18,6 +19,7 @@ export const paramDef = { export default define(meta, paramDef, async () => { const memStats = await si.mem(); const fsStats = await si.fsSize(); + const meilisearchStats = await meilisearchStatus(); return { machine: os.hostname(), @@ -32,5 +34,15 @@ export default define(meta, paramDef, async () => { total: fsStats[0].size, used: fsStats[0].used, }, + meilisearch: meilisearchStats + }; }); + +async function meilisearchStatus() { + if (meilisearch) { + return meilisearch.serverStats(); + } else { + return null; + } +} diff --git a/packages/client/src/widgets/server-metric/disk.vue b/packages/client/src/widgets/server-metric/disk.vue index 67ea398c1..0457cf7f0 100644 --- a/packages/client/src/widgets/server-metric/disk.vue +++ b/packages/client/src/widgets/server-metric/disk.vue @@ -8,6 +8,12 @@

Used: {{ bytes(used, 1) }}

+
+
+

MeiliSearch

+ +
+