feat(monitor): 自 go-hua 迁入系统资源监控

- Start 后台每秒采集(CPU/内存/磁盘/网络/进程/连接/主机), GetInfo 取快照
- 基于 gopsutil, 附测试、examples/monitor 例程与包 README
This commit is contained in:
2026-09-20 12:29:37 +08:00
parent 138c929bd4
commit 30a0889ffa
11 changed files with 963 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package monitor
import (
"strings"
"github.com/shirou/gopsutil/v3/host"
)
// HostInfo 主机信息(主机名/系统/开机时长等,gopsutil host.InfoStat)
type HostInfo struct {
HostName string `json:"hostName"`
Uptime uint64 `json:"uptime"`
BootTime uint64 `json:"bootTime"`
Procs uint64 `json:"procs"`
Os string `json:"os"`
Platform string `json:"platform"`
}
// getHostInfo 采集主机信息
func getHostInfo() (HostInfo, error) {
info := HostInfo{}
h, err := host.Info()
if err != nil {
return info, err
}
info.HostName = h.Hostname
info.Uptime = h.Uptime
info.BootTime = h.BootTime
info.Procs = h.Procs
info.Os = h.OS
info.Platform = strings.Trim(strings.Replace(h.Platform, "Microsoft", "", -1), " ")
return info, nil
}