fix: 概览页获取 CPU 精度问题 (#6380)

Refs #6309
This commit is contained in:
2024-09-05 16:39:48 +08:00 committed by GitHub
parent 1173bbf628
commit feb6f4cbe0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,12 +151,12 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d
currentInfo.Procs = hostInfo.Procs
currentInfo.CPUTotal, _ = cpu.Counts(true)
totalPercent, _ := cpu.Percent(0, false)
totalPercent, _ := cpu.Percent(1*time.Second, false)
if len(totalPercent) == 1 {
currentInfo.CPUUsedPercent = totalPercent[0]
currentInfo.CPUUsed = currentInfo.CPUUsedPercent * 0.01 * float64(currentInfo.CPUTotal)
}
currentInfo.CPUPercent, _ = cpu.Percent(0, true)
currentInfo.CPUPercent, _ = cpu.Percent(1*time.Second, true)
loadInfo, _ := load.Avg()
currentInfo.Load1 = loadInfo.Load1