|
@@ -8,16 +8,19 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+// GetCpuPercent cpu总占用率
|
|
|
func GetCpuPercent() float64 {
|
|
|
percent, _ := cpu.Percent(time.Second, false)
|
|
|
return percent[0]
|
|
|
}
|
|
|
|
|
|
+// GetMemoryPercent 内存总占用率
|
|
|
func GetMemoryPercent() float64 {
|
|
|
memory, _ := mem.SwapMemory()
|
|
|
return memory.UsedPercent
|
|
|
}
|
|
|
|
|
|
+// GetDiskPercent 磁盘总占用率
|
|
|
func GetDiskPercent() float64 {
|
|
|
parts, _ := disk.Partitions(true)
|
|
|
diskInfo, _ := disk.Usage(parts[0].Mountpoint)
|
|
@@ -25,7 +28,7 @@ func GetDiskPercent() float64 {
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
- fmt.Println("cpu总占用为:", GetCpuPercent())
|
|
|
- fmt.Println("内存总占用为:", GetMemoryPercent())
|
|
|
- fmt.Println("磁盘总占用为:", GetDiskPercent())
|
|
|
+ fmt.Println("cpu总占用率为:", GetCpuPercent())
|
|
|
+ fmt.Println("内存总占用率为:", GetMemoryPercent())
|
|
|
+ fmt.Println("磁盘总占用率为:", GetDiskPercent())
|
|
|
}
|