后台优化

This commit is contained in:
hahwu 2025-12-30 15:55:19 +08:00
parent 83568e3c23
commit 5c0ea843a0

View File

@ -219,15 +219,16 @@ func ReqServerInfo(args []interface{}) error {
runtime.ReadMemStats(&m) runtime.ReadMemStats(&m)
res["TotalAlloc"] = fmt.Sprintf("%dM", m.TotalAlloc/(1024*1024)) res["TotalAlloc"] = fmt.Sprintf("%dM", m.TotalAlloc/(1024*1024))
// 2. 获取系统内存使用信息 // 2. 获取系统内存使用信息
vmStat, err := mem.VirtualMemory() vmStat, _ := mem.VirtualMemory()
if err == nil {
res["Sys"] = fmt.Sprintf("%.2f%%", vmStat.UsedPercent)
}
// 3. 获取 CPU 使用率(一秒内采样) // 3. 获取 CPU 使用率(一秒内采样)
cpuPercent, err := cpu.Percent(time.Second, false) cpuPercent, err := cpu.Percent(time.Second, false)
if err == nil && len(cpuPercent) > 0 { if err == nil && len(cpuPercent) > 0 {
res["CPU"] = cpuPercent[0] res["CPU"] = cpuPercent[0]
} }
res["Alloc"] = fmt.Sprintf("%dM", m.Alloc/(1024*1024))
res["Sys"] = m.Sys / (1024 * 1024)
res["NumGC"] = m.NumGC
res["NumGoroutine"] = runtime.NumGoroutine()
if vmStat != nil { if vmStat != nil {
res["FreeMem"] = vmStat.Available / (1024 * 1024) res["FreeMem"] = vmStat.Available / (1024 * 1024)
res["UsageMem"] = vmStat.Used / (1024 * 1024) res["UsageMem"] = vmStat.Used / (1024 * 1024)