2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2021-01-03 14:38:32 +01:00
|
|
|
<template>
|
2023-05-29 10:13:12 +02:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" :naked="widgetProps.transparent">
|
2023-01-15 00:30:29 +01:00
|
|
|
<template #icon><i class="ti ti-server"></i></template>
|
|
|
|
<template #header>{{ i18n.ts._widgets.serverMetric }}</template>
|
|
|
|
<template #func="{ buttonStyleClass }"><button class="_button" :class="buttonStyleClass" @click="toggleView()"><i class="ti ti-selector"></i></button></template>
|
2021-01-03 14:38:32 +01:00
|
|
|
|
2023-03-09 11:59:11 +01:00
|
|
|
<div v-if="meta" data-cy-mkw-serverMetric class="mkw-serverMetric">
|
2022-01-08 12:30:01 +01:00
|
|
|
<XCpuMemory v-if="widgetProps.view === 0" :connection="connection" :meta="meta"/>
|
|
|
|
<XNet v-else-if="widgetProps.view === 1" :connection="connection" :meta="meta"/>
|
|
|
|
<XCpu v-else-if="widgetProps.view === 2" :connection="connection" :meta="meta"/>
|
|
|
|
<XMemory v-else-if="widgetProps.view === 3" :connection="connection" :meta="meta"/>
|
|
|
|
<XDisk v-else-if="widgetProps.view === 4" :connection="connection" :meta="meta"/>
|
2021-01-03 14:38:32 +01:00
|
|
|
</div>
|
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 15:09:41 +01:00
|
|
|
import { onUnmounted, ref } from 'vue';
|
2023-12-26 06:19:35 +01:00
|
|
|
import * as Misskey from 'misskey-js';
|
2024-01-07 15:56:46 +01:00
|
|
|
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from '../widget.js';
|
2021-01-03 14:38:32 +01:00
|
|
|
import XCpuMemory from './cpu-mem.vue';
|
|
|
|
import XNet from './net.vue';
|
|
|
|
import XCpu from './cpu.vue';
|
|
|
|
import XMemory from './mem.vue';
|
|
|
|
import XDisk from './disk.vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApiGet } from '@/scripts/misskey-api.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { useStream } from '@/stream.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2021-01-03 14:38:32 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'serverMetric';
|
2021-01-03 14:38:32 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2021-01-03 14:38:32 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2021-01-03 14:38:32 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
view: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 0,
|
|
|
|
hidden: true,
|
2021-01-03 14:38:32 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2024-01-07 15:56:46 +01:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2023-12-26 06:19:35 +01:00
|
|
|
const meta = ref<Misskey.entities.ServerInfoResponse | null>(null);
|
2022-01-08 12:30:01 +01:00
|
|
|
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApiGet('server-info', {}).then(res => {
|
2022-01-08 12:30:01 +01:00
|
|
|
meta.value = res;
|
|
|
|
});
|
|
|
|
|
|
|
|
const toggleView = () => {
|
2022-05-25 09:43:12 +02:00
|
|
|
if (widgetProps.view === 4) {
|
2022-01-08 12:30:01 +01:00
|
|
|
widgetProps.view = 0;
|
|
|
|
} else {
|
|
|
|
widgetProps.view++;
|
2021-01-03 14:38:32 +01:00
|
|
|
}
|
2022-01-08 12:30:01 +01:00
|
|
|
save();
|
|
|
|
};
|
|
|
|
|
2023-05-15 12:08:46 +02:00
|
|
|
const connection = useStream().useChannel('serverStats');
|
2022-01-08 12:30:01 +01:00
|
|
|
onUnmounted(() => {
|
|
|
|
connection.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2021-01-03 14:38:32 +01:00
|
|
|
});
|
|
|
|
</script>
|