Add Meilisearch widget
This commit is contained in:
parent
4f07c88abb
commit
a33b548555
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
<p>Used: {{ bytes(used, 1) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="ms_stats">
|
||||
<p>MeiliSearch</p>
|
||||
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
@ -26,6 +32,18 @@ const available = $computed(() => props.meta.fs.total - props.meta.fs.used);
|
|||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.ms_stats {
|
||||
padding: 16px;
|
||||
|
||||
> div {
|
||||
> p {
|
||||
&:first-child {
|
||||
font-weight: bold;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.zbwaqsat {
|
||||
display: flex;
|
||||
padding: 16px;
|
||||
|
|
|
@ -38,6 +38,11 @@
|
|||
:connection="connection"
|
||||
:meta="meta"
|
||||
/>
|
||||
<XMeili
|
||||
v-else-if="widgetProps.view === 5"
|
||||
:connection="connection"
|
||||
:meta="meta"
|
||||
/>
|
||||
</div>
|
||||
</MkContainer>
|
||||
</template>
|
||||
|
@ -56,6 +61,7 @@ import XNet from "./net.vue";
|
|||
import XCpu from "./cpu.vue";
|
||||
import XMemory from "./mem.vue";
|
||||
import XDisk from "./disk.vue";
|
||||
import XMeili from "./meilisearch.vue"
|
||||
import MkContainer from "@/components/MkContainer.vue";
|
||||
import { GetFormResultType } from "@/scripts/form";
|
||||
import * as os from "@/os";
|
||||
|
@ -102,7 +108,7 @@ os.api("server-info", {}).then((res) => {
|
|||
});
|
||||
|
||||
const toggleView = () => {
|
||||
if (widgetProps.view === 4) {
|
||||
if (widgetProps.view === 5) {
|
||||
widgetProps.view = 0;
|
||||
} else {
|
||||
widgetProps.view++;
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue