使用 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
}
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)
}
}