2021-01-03 14:38:32 +01:00
|
|
|
<template>
|
|
|
|
<MkContainer :show-header="props.showHeader" :naked="props.transparent">
|
2021-04-20 16:22:59 +02:00
|
|
|
<template #header><i class="fas fa-server"></i>{{ $ts._widgets.serverMetric }}</template>
|
2021-11-19 11:36:12 +01:00
|
|
|
<template #func><button class="_button" @click="toggleView()"><i class="fas fa-sort"></i></button></template>
|
2021-01-03 14:38:32 +01:00
|
|
|
|
2021-11-19 11:36:12 +01:00
|
|
|
<div v-if="meta" class="mkw-serverMetric">
|
2021-01-03 14:38:32 +01:00
|
|
|
<XCpuMemory v-if="props.view === 0" :connection="connection" :meta="meta"/>
|
|
|
|
<XNet v-if="props.view === 1" :connection="connection" :meta="meta"/>
|
|
|
|
<XCpu v-if="props.view === 2" :connection="connection" :meta="meta"/>
|
|
|
|
<XMemory v-if="props.view === 3" :connection="connection" :meta="meta"/>
|
|
|
|
<XDisk v-if="props.view === 4" :connection="connection" :meta="meta"/>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-07-26 04:12:06 +02:00
|
|
|
import { defineComponent, markRaw } from 'vue';
|
2021-01-03 14:38:32 +01:00
|
|
|
import define from '../define';
|
2021-11-11 18:02:25 +01:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
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';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
2021-01-03 14:38:32 +01:00
|
|
|
|
|
|
|
const widget = define({
|
|
|
|
name: 'serverMetric',
|
|
|
|
props: () => ({
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
view: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
MkContainer,
|
|
|
|
XCpuMemory,
|
|
|
|
XNet,
|
|
|
|
XCpu,
|
|
|
|
XMemory,
|
|
|
|
XDisk,
|
|
|
|
},
|
2021-11-19 11:36:12 +01:00
|
|
|
extends: widget,
|
2021-01-03 14:38:32 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
meta: null,
|
|
|
|
connection: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
os.api('server-info', {}).then(res => {
|
|
|
|
this.meta = res;
|
|
|
|
});
|
2021-07-26 04:12:06 +02:00
|
|
|
this.connection = markRaw(os.stream.useChannel('serverStats'));
|
2021-01-03 14:38:32 +01:00
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
this.connection.dispose();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggleView() {
|
|
|
|
if (this.props.view == 4) {
|
|
|
|
this.props.view = 0;
|
|
|
|
} else {
|
|
|
|
this.props.view++;
|
|
|
|
}
|
|
|
|
this.save();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|