使用 Usage 替换 Percent.

Signed-off-by: chen.yang <chen.yang@yuzhen-iot.com>
This commit is contained in:
chen.yang 2021-08-19 15:46:31 +08:00
parent 5bcaaba508
commit 2a686da658
1 changed files with 10 additions and 10 deletions

View File

@ -42,19 +42,19 @@ func GetModelName(idx int) string {
return cpuInfo[idx].ModelName return cpuInfo[idx].ModelName
} }
func GetCpuPercent() float64 { func GetCpuUsage() float64 {
percent, _ := cpu.Percent(time.Second, false) percent, _ := cpu.Percent(time.Second, false)
return percent[0] return percent[0]
} }
func GetMemPercent() float64 { func GetMemUsage() float64 {
memInfo, _ := mem.VirtualMemory() info, _ := mem.VirtualMemory()
return 100.0 * float64(memInfo.Total-memInfo.Available) / float64(memInfo.Total) return 100.0 * float64(info.Total-info.Available) / float64(info.Total)
} }
func GetDiskPercent() float64 { func GetDiskUsage() float64 {
diskInfo, _ := disk.Usage("/") info, _ := disk.Usage("/")
return diskInfo.UsedPercent return info.UsedPercent
} }
func GetNetStat() []net.ConnectionStat { func GetNetStat() []net.ConnectionStat {
@ -86,9 +86,9 @@ func main() {
fmt.Println("PID: ", GetPIDs()) fmt.Println("PID: ", GetPIDs())
fmt.Println("Process: ", GetProcessInfo()) fmt.Println("Process: ", GetProcessInfo())
for { for {
fmt.Println("CPU: ", GetCpuPercent()) fmt.Println("CPU: ", GetCpuUsage())
fmt.Println("Mem: ", GetMemPercent()) fmt.Println("Mem: ", GetMemUsage())
fmt.Println("Dsk: ", GetDiskPercent()) fmt.Println("Dsk: ", GetDiskUsage())
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
} }