Some checks failed
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-frontend (push) Has been cancelled
- 在App.vue中新增服务端更新模态框和相关功能 - 添加applyServerUpdate API调用和更新确认对话框 - 实现客户端版本信息显示和更新检测功能 - 添加系统状态监控包括CPU、内存和磁盘使用情况 - 新增getClientSystemStats API接口获取客户端系统统计信息 - 更新go.mod和go.sum文件添加必要的依赖包 - 优化UI界面样式和交互体验
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"time"
|
|
|
|
"github.com/shirou/gopsutil/v3/cpu"
|
|
"github.com/shirou/gopsutil/v3/disk"
|
|
"github.com/shirou/gopsutil/v3/mem"
|
|
)
|
|
|
|
// SystemStats 系统状态信息
|
|
type SystemStats struct {
|
|
CPUUsage float64 `json:"cpu_usage"`
|
|
MemoryTotal uint64 `json:"memory_total"`
|
|
MemoryUsed uint64 `json:"memory_used"`
|
|
MemoryUsage float64 `json:"memory_usage"`
|
|
DiskTotal uint64 `json:"disk_total"`
|
|
DiskUsed uint64 `json:"disk_used"`
|
|
DiskUsage float64 `json:"disk_usage"`
|
|
}
|
|
|
|
// GetSystemStats 获取系统状态信息
|
|
func GetSystemStats() (*SystemStats, error) {
|
|
stats := &SystemStats{}
|
|
|
|
// CPU 使用率
|
|
cpuPercent, err := cpu.Percent(time.Second, false)
|
|
if err == nil && len(cpuPercent) > 0 {
|
|
stats.CPUUsage = cpuPercent[0]
|
|
}
|
|
|
|
// 内存信息
|
|
memInfo, err := mem.VirtualMemory()
|
|
if err == nil {
|
|
stats.MemoryTotal = memInfo.Total
|
|
stats.MemoryUsed = memInfo.Used
|
|
stats.MemoryUsage = memInfo.UsedPercent
|
|
}
|
|
|
|
// 磁盘信息 - 获取根目录或当前工作目录所在磁盘
|
|
diskPath := "/"
|
|
if runtime.GOOS == "windows" {
|
|
// Windows 使用当前工作目录所在盘符
|
|
if wd, err := os.Getwd(); err == nil && len(wd) >= 2 {
|
|
diskPath = wd[:2] + "\\"
|
|
} else {
|
|
diskPath = "C:\\"
|
|
}
|
|
}
|
|
|
|
diskInfo, err := disk.Usage(diskPath)
|
|
if err == nil {
|
|
stats.DiskTotal = diskInfo.Total
|
|
stats.DiskUsed = diskInfo.Used
|
|
stats.DiskUsage = diskInfo.UsedPercent
|
|
}
|
|
|
|
return stats, nil
|
|
}
|