2014-08-08 22:09:28 +08:00
|
|
|
// +build freebsd linux darwin
|
2014-04-18 15:34:47 +08:00
|
|
|
|
2014-04-22 08:44:22 +08:00
|
|
|
package gopsutil
|
2014-04-18 15:34:47 +08:00
|
|
|
|
|
|
|
import "syscall"
|
|
|
|
|
2014-05-01 14:47:46 +08:00
|
|
|
func DiskUsage(path string) (*DiskUsageStat, error) {
|
2014-04-18 15:34:47 +08:00
|
|
|
stat := syscall.Statfs_t{}
|
|
|
|
err := syscall.Statfs(path, &stat)
|
|
|
|
if err != nil {
|
2014-05-01 14:47:46 +08:00
|
|
|
return nil, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
|
2014-10-10 16:09:36 +08:00
|
|
|
bsize := stat.Bsize
|
2014-04-18 15:34:47 +08:00
|
|
|
|
2014-05-01 14:47:46 +08:00
|
|
|
ret := &DiskUsageStat{
|
2014-08-26 21:17:35 +08:00
|
|
|
Path: path,
|
2014-10-10 16:09:36 +08:00
|
|
|
Total: (uint64(stat.Blocks) * uint64(bsize)),
|
|
|
|
Free: (uint64(stat.Bfree) * uint64(bsize)),
|
2014-08-26 16:38:52 +08:00
|
|
|
InodesTotal: (uint64(stat.Files)),
|
2014-08-26 21:17:35 +08:00
|
|
|
InodesFree: (uint64(stat.Ffree)),
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
|
2014-08-26 16:38:52 +08:00
|
|
|
ret.InodesUsed = (ret.InodesTotal - ret.InodesFree)
|
|
|
|
ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0
|
2014-04-18 15:34:47 +08:00
|
|
|
ret.Used = (ret.Total - ret.Free)
|
2014-04-22 08:48:19 +08:00
|
|
|
ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0
|
2014-04-18 15:34:47 +08:00
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|