Add Meilisearch widget

This commit is contained in:
PrivateGER 2023-05-25 09:53:04 +02:00 committed by PrivateGER
parent 4f07c88abb
commit a33b548555
6 changed files with 112 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import si from "systeminformation"; import si from "systeminformation";
import Xev from "xev"; import Xev from "xev";
import * as osUtils from "os-utils"; import * as osUtils from "os-utils";
import meilisearch from "../db/meilisearch";
const ev = new Xev(); const ev = new Xev();
@ -24,6 +25,7 @@ export default function () {
const memStats = await mem(); const memStats = await mem();
const netStats = await net(); const netStats = await net();
const fsStats = await fs(); const fsStats = await fs();
const meilisearchStats = await meilisearchStatus();
const stats = { const stats = {
cpu: roundCpu(cpu), cpu: roundCpu(cpu),
@ -39,6 +41,7 @@ export default function () {
r: round(Math.max(0, fsStats.rIO_sec ?? 0)), r: round(Math.max(0, fsStats.rIO_sec ?? 0)),
w: round(Math.max(0, fsStats.wIO_sec ?? 0)), w: round(Math.max(0, fsStats.wIO_sec ?? 0)),
}, },
meilisearch: meilisearchStats
}; };
ev.emit("serverStats", stats); ev.emit("serverStats", stats);
log.unshift(stats); log.unshift(stats);
@ -77,3 +80,11 @@ async function fs() {
const data = await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 })); const data = await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 }));
return data || { 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;
}
}

View File

@ -1,4 +1,4 @@
import { MeiliSearch } from 'meilisearch'; import {Health, MeiliSearch, Stats } from 'meilisearch';
import { dbLogger } from "./logger.js"; import { dbLogger } from "./logger.js";
import config from "@/config/index.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 port = hasConfig ? config.meilisearch.port ?? 7700 : 0;
const auth = hasConfig ? config.meilisearch.apiKey ?? "" : ""; const auth = hasConfig ? config.meilisearch.apiKey ?? "" : "";
const client = new MeiliSearch({ const client : MeiliSearch = new MeiliSearch({
host: `http://${host}:${port}`, host: `http://${host}:${port}`,
apiKey: auth, apiKey: auth,
}) })
@ -58,6 +58,16 @@ export default hasConfig ? {
userHost: note.userHost, userHost: note.userHost,
channelId: note.channelId, 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; } : null;

View File

@ -1,6 +1,7 @@
import * as os from "node:os"; import * as os from "node:os";
import si from "systeminformation"; import si from "systeminformation";
import define from "../define.js"; import define from "../define.js";
import meilisearch from "../../../db/meilisearch";
export const meta = { export const meta = {
requireCredential: false, requireCredential: false,
@ -18,6 +19,7 @@ export const paramDef = {
export default define(meta, paramDef, async () => { export default define(meta, paramDef, async () => {
const memStats = await si.mem(); const memStats = await si.mem();
const fsStats = await si.fsSize(); const fsStats = await si.fsSize();
const meilisearchStats = await meilisearchStatus();
return { return {
machine: os.hostname(), machine: os.hostname(),
@ -32,5 +34,15 @@ export default define(meta, paramDef, async () => {
total: fsStats[0].size, total: fsStats[0].size,
used: fsStats[0].used, used: fsStats[0].used,
}, },
meilisearch: meilisearchStats
}; };
}); });
async function meilisearchStatus() {
if (meilisearch) {
return meilisearch.serverStats();
} else {
return null;
}
}

View File

@ -8,6 +8,12 @@
<p>Used: {{ bytes(used, 1) }}</p> <p>Used: {{ bytes(used, 1) }}</p>
</div> </div>
</div> </div>
<br />
<div class="ms_stats">
<p>MeiliSearch</p>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -26,6 +32,18 @@ const available = $computed(() => props.meta.fs.total - props.meta.fs.used);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.ms_stats {
padding: 16px;
> div {
> p {
&:first-child {
font-weight: bold;
margin-bottom: 4px;
}
}
}
}
.zbwaqsat { .zbwaqsat {
display: flex; display: flex;
padding: 16px; padding: 16px;

View File

@ -38,6 +38,11 @@
:connection="connection" :connection="connection"
:meta="meta" :meta="meta"
/> />
<XMeili
v-else-if="widgetProps.view === 5"
:connection="connection"
:meta="meta"
/>
</div> </div>
</MkContainer> </MkContainer>
</template> </template>
@ -56,6 +61,7 @@ import XNet from "./net.vue";
import XCpu from "./cpu.vue"; import XCpu from "./cpu.vue";
import XMemory from "./mem.vue"; import XMemory from "./mem.vue";
import XDisk from "./disk.vue"; import XDisk from "./disk.vue";
import XMeili from "./meilisearch.vue"
import MkContainer from "@/components/MkContainer.vue"; import MkContainer from "@/components/MkContainer.vue";
import { GetFormResultType } from "@/scripts/form"; import { GetFormResultType } from "@/scripts/form";
import * as os from "@/os"; import * as os from "@/os";
@ -102,7 +108,7 @@ os.api("server-info", {}).then((res) => {
}); });
const toggleView = () => { const toggleView = () => {
if (widgetProps.view === 4) { if (widgetProps.view === 5) {
widgetProps.view = 0; widgetProps.view = 0;
} else { } else {
widgetProps.view++; widgetProps.view++;

View File

@ -0,0 +1,51 @@
<template>
<div class="ms_stats">
<div>
<p><i class="ph-file-search ph-bold ph-lg"></i>MeiliSearch</p>
<p>Server Status: {{ available }}</p>
<p>Total: {{ bytes(total_size, 1) }}</p>
<p>Posts Indexed: {{ index_count }}</p>
</div>
</div>
<br />
<div class="ms_stats">
<p>MeiliSearch</p>
</div>
</template>
<script lang="ts" setup>
import {} from "vue";
import bytes from "@/filters/bytes";
const props = defineProps<{
meta: any; // TODO
}>();
const total_size = $computed(() => props.meta.meilisearch.total);
const index_count = $computed(() => props.meta.meilisearch.indexed_count);
const available = $computed(() => props.meta.meilisearch.available);
</script>
<style lang="scss" scoped>
.ms_stats {
padding: 16px;
> div {
> p {
margin: 0;
font-size: 0.8em;
&:first-child {
font-weight: bold;
margin-bottom: 4px;
> i {
margin-right: 4px;
}
}
}
}
}
</style>