gopsutil库获取Cpu、Mem、Disk

gopsutil库获取Cpu、Mem、Disk


package main
import (
   "github.com/shirou/gopsutil/cpu"
   "github.com/shirou/gopsutil/disk"
   "github.com/shirou/gopsutil/mem"
   "time"
)

func GetCpuPercent() float64  {
   percent, _ := cpu.Percent(time.Second)
   return percent[0]
}

func GetMemPercent() float64  {
   memInfo, _ := mem.VirtualMemory()
   return memInfo
}

func GetDiskPercent() float64  {
   parts, _ := disk.Partitions(true)
   diskInfo, _ := disk.Usage(parts[0].Mountpoint)
   return diskInfo.UsedPercent

}
func main() {
   GetMemPercent()
   GetCpuPercent()
   GetDiskPercent()
}

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:设计师小姐姐 返回首页