seaweedfs/go/stats/disk.go

28 lines
437 B
Go
Raw Normal View History

// +build !windows
package stats
import (
"syscall"
)
type DiskStatus struct {
2014-03-26 20:22:27 +00:00
Dir string
All uint64
Used uint64
Free uint64
}
2014-03-26 20:22:27 +00:00
func NewDiskStatus(path string) (disk *DiskStatus) {
disk = &DiskStatus{Dir: path}
fs := syscall.Statfs_t{}
err := syscall.Statfs(path, &fs)
if err != nil {
return
}
disk.All = fs.Blocks * uint64(fs.Bsize)
disk.Free = fs.Bfree * uint64(fs.Bsize)
disk.Used = disk.All - disk.Free
return
}