diff --git a/service/global/monitor.go b/service/global/monitor.go index a1f03f4..daaa42c 100644 --- a/service/global/monitor.go +++ b/service/global/monitor.go @@ -3,8 +3,8 @@ package global import "sun-panel/lib/monitor" type ModelSystemMonitor struct { - CPUInfo monitor.CPUInfo - DiskInfo []monitor.DiskInfo - NetIOCountersInfo []monitor.NetIOCountersInfo - MemoryInfo monitor.MemoryInfo + CPUInfo monitor.CPUInfo `json:"cpuInfo"` + DiskInfo []monitor.DiskInfo `json:"diskInfo"` + NetIOCountersInfo []monitor.NetIOCountersInfo `json:"netIOCountersInfo"` + MemoryInfo monitor.MemoryInfo `json:"memoryInfo"` } diff --git a/service/lib/monitor/monitor.go b/service/lib/monitor/monitor.go index 7ab8419..16c29df 100644 --- a/service/lib/monitor/monitor.go +++ b/service/lib/monitor/monitor.go @@ -31,14 +31,17 @@ type NetIOCountersInfo struct { } type MemoryInfo struct { - Total uint64 `json:"total"` - Free uint64 `json:"free"` + Total uint64 `json:"total"` + Free uint64 `json:"free"` + Used uint64 `json:"used"` + UsedPercent float64 `json:"usedPercent"` } // 获取CPU信息 func GetCPUInfo() (CPUInfo, error) { cpuInfoRes := CPUInfo{} cpuInfo, err := cpu.Info() + if err == nil && len(cpuInfo) > 0 { cpuInfoRes.CoreCount = cpuInfo[0].Cores cpuInfoRes.Model = cpuInfo[0].ModelName @@ -59,6 +62,8 @@ func GetMemoryInfo() (MemoryInfo, error) { if err == nil { memoryInfo.Free = memInfo.Free memoryInfo.Total = memInfo.Total + memoryInfo.Used = memInfo.Used + memoryInfo.UsedPercent = memInfo.UsedPercent } return memoryInfo, err diff --git a/src/api/system/systemMonitor.ts b/src/api/system/systemMonitor.ts new file mode 100644 index 0000000..c7f6b20 --- /dev/null +++ b/src/api/system/systemMonitor.ts @@ -0,0 +1,7 @@ +import { post } from '@/utils/request' + +export function getAll() { + return post({ + url: '/system/monitor/getAll', + }) +} diff --git a/src/assets/svg-icons/clarity-hard-disk-solid.svg b/src/assets/svg-icons/clarity-hard-disk-solid.svg new file mode 100644 index 0000000..f97333e --- /dev/null +++ b/src/assets/svg-icons/clarity-hard-disk-solid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/svg-icons/material-symbols-memory-alt-rounded.svg b/src/assets/svg-icons/material-symbols-memory-alt-rounded.svg new file mode 100644 index 0000000..0f5dcfa --- /dev/null +++ b/src/assets/svg-icons/material-symbols-memory-alt-rounded.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/svg-icons/solar-cpu-bold.svg b/src/assets/svg-icons/solar-cpu-bold.svg new file mode 100644 index 0000000..590f39d --- /dev/null +++ b/src/assets/svg-icons/solar-cpu-bold.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/deskModule/SystemMonitor/index.vue b/src/components/deskModule/SystemMonitor/index.vue new file mode 100644 index 0000000..88588d2 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/index.vue @@ -0,0 +1,162 @@ + + + diff --git a/src/components/deskModule/index.ts b/src/components/deskModule/index.ts index 92c8882..5f85ba7 100644 --- a/src/components/deskModule/index.ts +++ b/src/components/deskModule/index.ts @@ -1,4 +1,5 @@ import Clock from './Clock/index.vue' import SearchBox from './SearchBox/index.vue' +import SystemMonitor from './SystemMonitor/index.vue' -export { Clock, SearchBox } +export { Clock, SearchBox, SystemMonitor } diff --git a/src/typings/systemMonitor.d.ts b/src/typings/systemMonitor.d.ts new file mode 100644 index 0000000..99def4a --- /dev/null +++ b/src/typings/systemMonitor.d.ts @@ -0,0 +1,37 @@ +declare namespace SystemMonitor { + + interface CPUInfo { + coreCount: number + cpuNum: number + model: string + usages: number[] + } + + interface DiskInfo { + mountpoint: string + total: number + used: number + free: number + usedPercent: number + } + + interface NetIOCountersInfo { + bytesSent: number + bytesRecv: number + name: string + } + + interface MemoryInfo { + total: number + used: number + free: number + usedPercent: number + } + + interface GetAllRes { + cpuInfo: CPUInfo + diskInfo: DiskInfo[] + netIOCountersInfo: NetIOCountersInfo[] + memoryInfo: MemoryInfo + } +} \ No newline at end of file diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 465e2be..9d3c46e 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -3,7 +3,7 @@ import { VueDraggable } from 'vue-draggable-plus' import { NBackTop, NButton, NButtonGroup, NDropdown, NModal, NSkeleton, NSpin, useDialog, useMessage } from 'naive-ui' import { nextTick, onMounted, ref } from 'vue' import { AppIcon, AppStarter, EditItem } from './components' -import { Clock, SearchBox } from '@/components/deskModule' +import { Clock, SearchBox, SystemMonitor } from '@/components/deskModule' import { SvgIcon } from '@/components/common' import { deletes, getListByGroupId, saveSort } from '@/api/panel/itemIcon' import { getList as getGroupList } from '@/api/panel/itemIconGroup' @@ -363,6 +363,10 @@ function handleAddItem(itemIconGroupId?: number) {
+
+ +
+