This commit is contained in:
qiangyanwen 2022-12-13 16:20:52 +08:00
parent f2a78738ab
commit 9dc732be28
3 changed files with 73 additions and 39 deletions

View File

@ -13,6 +13,7 @@ import {createPinia} from "pinia";
const pina = createPinia() const pina = createPinia()
import piniaPluginPersist from 'pinia-plugin-persist' import piniaPluginPersist from 'pinia-plugin-persist'
pina.use(piniaPluginPersist) pina.use(piniaPluginPersist)
// eslint-disable-next-line vue/multi-word-component-names
app.component("Echarts",Echarts) app.component("Echarts",Echarts)
app.config.globalProperties.$mitt = mitt(); app.config.globalProperties.$mitt = mitt();
app.use(Antd) app.use(Antd)

View File

@ -4,7 +4,7 @@ import {useRouter} from "vue-router";
import NProgress from "nprogress" import NProgress from "nprogress"
const service = axios.create({ const service = axios.create({
baseURL: 'http://192.168.9.93:8000/api', baseURL: 'http://127.0.0.1:8000/api',
timeout: 5000 timeout: 5000
}); });
const router = useRouter() const router = useRouter()

View File

@ -20,7 +20,7 @@
</a-col> </a-col>
<a-col :span="6"> <a-col :span="6">
<a-card title="磁盘分区" :bordered="false" class="disk"> <a-card title="磁盘分区" :bordered="false" class="disk">
<a-table :columns="columns" :data-source="data" size="middle" :pagination="false"/> <a-table :columns="columns" :data-source="disk.data" size="middle" :pagination="false"/>
</a-card> </a-card>
</a-col> </a-col>
@ -30,7 +30,6 @@
<script setup> <script setup>
import {onMounted, reactive, ref} from "vue"; import {onMounted, reactive, ref} from "vue";
import {Cpu, SysInfo, disk} from "@/api/monitor"
let sysparams = reactive({ let sysparams = reactive({
count: 0, count: 0,
@ -60,7 +59,7 @@ const option = reactive({
] ]
}) })
const memory = ref({ const memory = reactive({
tooltip: { tooltip: {
formatter: '{a} <br/>{b} : {c}%' formatter: '{a} <br/>{b} : {c}%'
}, },
@ -100,29 +99,64 @@ const columns = [{
dataIndex: "free", dataIndex: "free",
} }
]; ];
onMounted(() => { onMounted(() => {
QuerySys()
QueryCpu()
QueryDisk()
setInterval(() => { setInterval(() => {
QuerySys(); console.log("=======wwww")
QueryCpu(); GetSytem()
}, 5000) }, 5000)
})
const disk = reactive({
data:[]
}) })
function QuerySys() { function GetSytem(){
SysInfo().then((response) => { const ws = new WebSocket("ws://127.0.0.1:8000/api/ws")
if (response.code === 200) { console.log('=====>ws-=====',ws)
let {count, name, current_time, start_time} = response.data ws.onopen = function () { ws.send("")};
ws.onmessage = function (e){
const data = JSON.parse(e.data)
let {cpu_percent} = data.cpu_info
let {percent} = data.memory_info
option.series.forEach((data) => {
data.data.forEach((key) => {
key.value = cpu_percent
})
})
memory.series.forEach((data) => {
data.data.forEach((key) => {
key.value = percent
})
})
let {count, name, current_time, start_time} = data.sys_info
sysparams.count = count sysparams.count = count
sysparams.name = name sysparams.name = name
sysparams.current_time = current_time sysparams.current_time = current_time
let data_array = reactive([])
sysparams.start_time = start_time sysparams.start_time = start_time
data.disk_info.map((par, index) => {
let params = {
key: String(index),
device: par.device,
total: par.total,
used: par.used,
free: par.free,
} }
if (index < 5) {
data_array.push(params)
}
}) })
disk.data=data_array
}
} }
const QueryCpu = () => { const QueryCpu = () => {
Cpu().then((rep) => { Cpu().then((rep) => {
let {cpu_percent} = rep.data let {cpu_percent} = rep.data
@ -135,26 +169,25 @@ const QueryCpu = () => {
}) })
} }
const data = reactive([]) // const QueryDisk = () => {
const QueryDisk = () => { // disk().then((resp) => {
disk().then((resp) => { // resp.data.map((par, index) => {
resp.data.map((par, index) => { // let params = {
let params = { // key: String(index),
key: String(index), // device: par.device,
device: par.device, // total: par.total,
total: par.total, // used: par.used,
used: par.used, // free: par.free,
free: par.free, //
// }
} // if (index < 5) {
if (index < 5) { // data.push(params)
data.push(params) // }
} //
//
// })
}) // })
}) // }
}
</script> </script>