3.磁盘信息
()
| 78 | |
| 79 | // 3.磁盘信息 |
| 80 | func GetDiskInfo() (result Parts, err error) { |
| 81 | parts, err := disk.Partitions(true) |
| 82 | if err != nil { |
| 83 | return result, err |
| 84 | } |
| 85 | for _, part := range parts { |
| 86 | diskInfo, err := disk.Usage(part.Mountpoint) |
| 87 | if err == nil { |
| 88 | result = append(result, Part{ |
| 89 | Path: diskInfo.Path, |
| 90 | FsType: diskInfo.Fstype, |
| 91 | Total: decimal(fmt.Sprintf("%.2f", float64(diskInfo.Total/GB))), |
| 92 | Free: decimal(fmt.Sprintf("%.2f", float64(diskInfo.Free/GB))), |
| 93 | Used: decimal(fmt.Sprintf("%.2f", float64(diskInfo.Used/GB))), |
| 94 | UsedPercent: int(diskInfo.UsedPercent), |
| 95 | }) |
| 96 | } else { |
| 97 | return result, err |
| 98 | } |
| 99 | } |
| 100 | return result, err |
| 101 | } |
| 102 | |
| 103 | // 4.CPU使用率 |
| 104 | func GetCpuPercent() (result CpuInfo, err error) { |