fix: bug#12338

This commit is contained in:
xieyonghong 2023-04-26 18:05:23 +08:00
parent 84fa6f877b
commit ca4c364155
6 changed files with 81 additions and 41 deletions

View File

@ -61,6 +61,13 @@ import {
} from './tool.ts'; } from './tool.ts';
import { DataType } from '../typings'; import { DataType } from '../typings';
const props = defineProps({
serviceId: {
type: String,
default: undefined
}
})
const chartRef = ref<Record<string, any>>({}); const chartRef = ref<Record<string, any>>({});
const loading = ref(false); const loading = ref(false);
const data = ref<DataType>({ const data = ref<DataType>({
@ -79,7 +86,8 @@ const getCPUEcharts = async (val: any) => {
const _cpuOptions = {}; const _cpuOptions = {};
const _cpuXAxis = new Set(); const _cpuXAxis = new Set();
if (res.result?.length) { if (res.result?.length) {
res.result.forEach((item: any) => { const filterArray = res.result.filter((item : any) => item.data?.clusterNodeId === props.serviceId)
filterArray.forEach((item: any) => {
const value = item.data.value; const value = item.data.value;
const nodeID = item.data.clusterNodeId; const nodeID = item.data.clusterNodeId;
_cpuXAxis.add( _cpuXAxis.add(
@ -168,16 +176,14 @@ watch(
}, },
{ immediate: true, deep: true }, { immediate: true, deep: true },
); );
watch(
() => data.value, watchEffect(() => {
(val) => { const time = data.value.time
const { time } = val; if (time && Array.isArray(time) && time.length === 2 && time[0] && props.serviceId) {
if (time && Array.isArray(time) && time.length === 2 && time[0]) { getCPUEcharts(data.value);
getCPUEcharts(val);
} }
}, })
{ immediate: true, deep: true },
);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -61,6 +61,13 @@ import {
} from './tool.ts'; } from './tool.ts';
import { DataType } from '../typings'; import { DataType } from '../typings';
const props = defineProps({
serviceId: {
type: String,
default: undefined
}
})
const chartRef = ref<Record<string, any>>({}); const chartRef = ref<Record<string, any>>({});
const loading = ref(false); const loading = ref(false);
const data = ref<DataType>({ const data = ref<DataType>({
@ -79,7 +86,8 @@ const getJVMEcharts = async (val: any) => {
const _jvmOptions = {}; const _jvmOptions = {};
const _jvmXAxis = new Set(); const _jvmXAxis = new Set();
if (res.result?.length) { if (res.result?.length) {
res.result.forEach((item: any) => { const filterArray = res.result.filter((item : any) => item.data?.clusterNodeId === props.serviceId)
filterArray.forEach((item: any) => {
const value = item.data.value; const value = item.data.value;
const memoryJvmHeapFree = value.memoryJvmHeapFree; const memoryJvmHeapFree = value.memoryJvmHeapFree;
const memoryJvmHeapTotal = value.memoryJvmHeapTotal; const memoryJvmHeapTotal = value.memoryJvmHeapTotal;
@ -172,16 +180,14 @@ watch(
}, },
{ immediate: true, deep: true }, { immediate: true, deep: true },
); );
watch(
() => data.value, watchEffect(() => {
(val) => { const time = data.value.time
const { time } = val; if (time && Array.isArray(time) && time.length === 2 && time[0] && props.serviceId) {
if (time && Array.isArray(time) && time.length === 2 && time[0]) { getJVMEcharts(data.value);
getJVMEcharts(val);
} }
}, })
{ immediate: true, deep: true },
);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -69,6 +69,13 @@ import dayjs from 'dayjs';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import { DataType } from '../typings.d'; import { DataType } from '../typings.d';
const props = defineProps({
serviceId: {
type: String,
default: undefined
}
})
const chartRef = ref<Record<string, any>>({}); const chartRef = ref<Record<string, any>>({});
const loading = ref(false); const loading = ref(false);
const data = ref<DataType>({ const data = ref<DataType>({
@ -90,7 +97,8 @@ const getNetworkEcharts = async (val: any) => {
const _networkOptions = {}; const _networkOptions = {};
const _networkXAxis = new Set(); const _networkXAxis = new Set();
if (resp.result.length) { if (resp.result.length) {
resp.result.forEach((item: any) => { const filterArray = resp.result.filter((item : any) => item.data?.clusterNodeId === props.serviceId)
filterArray.forEach((item: any) => {
const value = item.data.value; const value = item.data.value;
const _data: Array<any> = []; const _data: Array<any> = [];
const nodeID = item.data.clusterNodeId; const nodeID = item.data.clusterNodeId;
@ -191,18 +199,14 @@ watch(
}, },
{ immediate: true, deep: true }, { immediate: true, deep: true },
); );
watch(
() => data.value, watchEffect(() => {
(value) => { const time = data.value.time.time
const { if (time && Array.isArray(time) && time.length === 2 && time[0] && props.serviceId) {
time: { time }, getNetworkEcharts(data.value);
} = value;
if (time && Array.isArray(time) && time.length === 2 && time[0]) {
getNetworkEcharts(value);
} }
}, })
{ immediate: true, deep: true },
);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -60,15 +60,26 @@ const topValues = ref({
systemUsage: 0, systemUsage: 0,
systemUsageTotal: 0, systemUsageTotal: 0,
}); });
const wsRef = ref<any>()
const emit = defineEmits(['serviceChange'])
const serverIdChange = (val: string) => { const serverIdChange = (val: string) => {
serverId.value = val; serverId.value = val;
}; };
const unSub = () => {
if (wsRef.value) {
wsRef.value.unsubscribe()
}
}
const getData = () => { const getData = () => {
const id = 'operations-statistics-system-info-realTime'; const id = 'operations-statistics-system-info-realTime';
const topic = '/dashboard/systemMonitor/stats/info/realTime'; const topic = '/dashboard/systemMonitor/stats/info/realTime';
getWebSocket(id, topic, { unSub()
wsRef.value = getWebSocket(id, topic, {
type: 'all', type: 'all',
serverNodeId: serverId.value, serverNodeId: serverId.value,
interval: '1s', interval: '1s',
@ -118,10 +129,16 @@ onMounted(() => {
}); });
} }
}); });
onUnmounted(() => {
unSub()
})
watch( watch(
() => serverId.value, () => serverId.value,
(val) => { (val) => {
val && getData(); val && getData();
emit('serviceChange', val)
}, },
); );
</script> </script>

View File

@ -2,10 +2,10 @@
<page-container> <page-container>
<div> <div>
<j-row :gutter="[24, 24]"> <j-row :gutter="[24, 24]">
<j-col :span="24"><TopCard /> </j-col> <j-col :span="24"><TopCard @serviceChange='serviceChange' /> </j-col>
<j-col :span="24"><Network /></j-col> <j-col :span="24"><Network :serviceId='serviceId' /></j-col>
<j-col :span="12"><Cpu /></j-col> <j-col :span="12"><Cpu :serviceId='serviceId'/></j-col>
<j-col :span="12"><Jvm /></j-col> <j-col :span="12"><Jvm :serviceId='serviceId'/></j-col>
</j-row> </j-row>
</div> </div>
</page-container> </page-container>
@ -16,6 +16,13 @@ import TopCard from './components/TopCard.vue';
import Network from './components/Network.vue'; import Network from './components/Network.vue';
import Cpu from './components/Cpu.vue'; import Cpu from './components/Cpu.vue';
import Jvm from './components/Jvm.vue'; import Jvm from './components/Jvm.vue';
const serviceId = ref<string | undefined>()
const serviceChange = (id: string) => {
serviceId.value = id
}
</script> </script>
<style lang="less" scoped></style> <style lang="less" scoped></style>