后台优化
This commit is contained in:
parent
83568e3c23
commit
5c0ea843a0
@ -219,15 +219,16 @@ func ReqServerInfo(args []interface{}) error {
|
||||
runtime.ReadMemStats(&m)
|
||||
res["TotalAlloc"] = fmt.Sprintf("%dM", m.TotalAlloc/(1024*1024))
|
||||
// 2. 获取系统内存使用信息
|
||||
vmStat, err := mem.VirtualMemory()
|
||||
if err == nil {
|
||||
res["Sys"] = fmt.Sprintf("%.2f%%", vmStat.UsedPercent)
|
||||
}
|
||||
vmStat, _ := mem.VirtualMemory()
|
||||
// 3. 获取 CPU 使用率(一秒内采样)
|
||||
cpuPercent, err := cpu.Percent(time.Second, false)
|
||||
if err == nil && len(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 {
|
||||
res["FreeMem"] = vmStat.Available / (1024 * 1024)
|
||||
res["UsageMem"] = vmStat.Used / (1024 * 1024)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user