feat(app): 添加服务端和客户端更新功能以及系统状态监控
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
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界面样式和交互体验
This commit is contained in:
@@ -71,6 +71,10 @@ const (
|
||||
// 插件 API 路由消息
|
||||
MsgTypePluginAPIRequest uint8 = 90 // 插件 API 请求
|
||||
MsgTypePluginAPIResponse uint8 = 91 // 插件 API 响应
|
||||
|
||||
// 系统状态消息
|
||||
MsgTypeSystemStatsRequest uint8 = 100 // 请求系统状态
|
||||
MsgTypeSystemStatsResponse uint8 = 101 // 系统状态响应
|
||||
)
|
||||
|
||||
// Message 基础消息结构
|
||||
@@ -83,8 +87,9 @@ type Message struct {
|
||||
type AuthRequest struct {
|
||||
ClientID string `json:"client_id"`
|
||||
Token string `json:"token"`
|
||||
OS string `json:"os,omitempty"` // 客户端操作系统
|
||||
Arch string `json:"arch,omitempty"` // 客户端架构
|
||||
OS string `json:"os,omitempty"` // 客户端操作系统
|
||||
Arch string `json:"arch,omitempty"` // 客户端架构
|
||||
Version string `json:"version,omitempty"` // 客户端版本
|
||||
}
|
||||
|
||||
// AuthResponse 认证响应
|
||||
@@ -441,3 +446,17 @@ func NewMessage(msgType uint8, data interface{}) (*Message, error) {
|
||||
func (m *Message) ParsePayload(v interface{}) error {
|
||||
return json.Unmarshal(m.Payload, v)
|
||||
}
|
||||
|
||||
// SystemStatsRequest 系统状态请求
|
||||
type SystemStatsRequest struct{}
|
||||
|
||||
// SystemStatsResponse 系统状态响应
|
||||
type SystemStatsResponse struct {
|
||||
CPUUsage float64 `json:"cpu_usage"` // CPU 使用率 (0-100)
|
||||
MemoryTotal uint64 `json:"memory_total"` // 总内存 (字节)
|
||||
MemoryUsed uint64 `json:"memory_used"` // 已用内存 (字节)
|
||||
MemoryUsage float64 `json:"memory_usage"` // 内存使用率 (0-100)
|
||||
DiskTotal uint64 `json:"disk_total"` // 总磁盘 (字节)
|
||||
DiskUsed uint64 `json:"disk_used"` // 已用磁盘 (字节)
|
||||
DiskUsage float64 `json:"disk_usage"` // 磁盘使用率 (0-100)
|
||||
}
|
||||
|
||||
61
pkg/utils/sysinfo.go
Normal file
61
pkg/utils/sysinfo.go
Normal file
@@ -0,0 +1,61 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user