适配显示了cpu、硬盘、内存信息

This commit is contained in:
Sun
2024-01-03 18:55:39 +08:00
parent 11ea134be3
commit fe967a9314
10 changed files with 227 additions and 8 deletions
+4 -4
View File
@@ -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"`
}
+7 -2
View File
@@ -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