diff --git a/Software/Development/Language/Go/Package/Gopsutil/Golang_获取硬件参数及_CPU_内存_硬盘的使用率.md b/Software/Development/Language/Go/Package/Gopsutil/Golang_获取硬件参数及_CPU_内存_硬盘的使用率.md index 4f630af..2f83597 100644 --- a/Software/Development/Language/Go/Package/Gopsutil/Golang_获取硬件参数及_CPU_内存_硬盘的使用率.md +++ b/Software/Development/Language/Go/Package/Gopsutil/Golang_获取硬件参数及_CPU_内存_硬盘的使用率.md @@ -42,19 +42,19 @@ func GetModelName(idx int) string { return cpuInfo[idx].ModelName } -func GetCpuPercent() float64 { +func GetCpuUsage() float64 { percent, _ := cpu.Percent(time.Second, false) return percent[0] } -func GetMemPercent() float64 { - memInfo, _ := mem.VirtualMemory() - return 100.0 * float64(memInfo.Total-memInfo.Available) / float64(memInfo.Total) +func GetMemUsage() float64 { + info, _ := mem.VirtualMemory() + return 100.0 * float64(info.Total-info.Available) / float64(info.Total) } -func GetDiskPercent() float64 { - diskInfo, _ := disk.Usage("/") - return diskInfo.UsedPercent +func GetDiskUsage() float64 { + info, _ := disk.Usage("/") + return info.UsedPercent } func GetNetStat() []net.ConnectionStat { @@ -86,9 +86,9 @@ func main() { fmt.Println("PID: ", GetPIDs()) fmt.Println("Process: ", GetProcessInfo()) for { - fmt.Println("CPU: ", GetCpuPercent()) - fmt.Println("Mem: ", GetMemPercent()) - fmt.Println("Dsk: ", GetDiskPercent()) + fmt.Println("CPU: ", GetCpuUsage()) + fmt.Println("Mem: ", GetMemUsage()) + fmt.Println("Dsk: ", GetDiskUsage()) time.Sleep(1 * time.Second) } }