49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
|
// Package system...
|
||
|
//
|
||
|
// Description : system...
|
||
|
//
|
||
|
// Author : go_developer@163.com<白茶清欢>
|
||
|
//
|
||
|
// Date : 2021-10-12 8:06 下午
|
||
|
package system
|
||
|
|
||
|
import (
|
||
|
"github.com/shirou/gopsutil/disk"
|
||
|
)
|
||
|
|
||
|
// GetDiskInfo 获取磁盘信息
|
||
|
//
|
||
|
// Author : go_developer@163.com<白茶清欢>
|
||
|
//
|
||
|
// Date : 8:06 下午 2021/10/12
|
||
|
func GetDiskInfo() (*OutputDiskInfo, error) {
|
||
|
var (
|
||
|
partitionList []disk.PartitionStat
|
||
|
diskUseStatList []*disk.UsageStat
|
||
|
err error
|
||
|
diskList []*DiskDetail
|
||
|
)
|
||
|
|
||
|
partitionList = make([]disk.PartitionStat, 0)
|
||
|
diskUseStatList = make([]*disk.UsageStat, 0)
|
||
|
diskList = make([]*DiskDetail, 0)
|
||
|
|
||
|
if partitionList, err = disk.Partitions(true); nil != err {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
for _, part := range partitionList {
|
||
|
diskInfo, _ := disk.Usage(part.Mountpoint)
|
||
|
diskList = append(diskList, &DiskDetail{
|
||
|
PartitionStat: part,
|
||
|
DiskStat: diskInfo,
|
||
|
})
|
||
|
diskUseStatList = append(diskUseStatList, diskInfo)
|
||
|
}
|
||
|
ioStat, _ := disk.IOCounters()
|
||
|
return &OutputDiskInfo{
|
||
|
DiskList: diskList,
|
||
|
IOStat: ioStat,
|
||
|
}, nil
|
||
|
}
|