disk_supported.go 646 B

123456789101112131415161718192021222324
  1. //go:build !windows && !openbsd && !netbsd && !plan9 && !solaris
  2. // +build !windows,!openbsd,!netbsd,!plan9,!solaris
  3. package stats
  4. import (
  5. "syscall"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
  7. )
  8. func fillInDiskStatus(disk *volume_server_pb.DiskStatus) {
  9. fs := syscall.Statfs_t{}
  10. err := syscall.Statfs(disk.Dir, &fs)
  11. if err != nil {
  12. return
  13. }
  14. disk.All = fs.Blocks * uint64(fs.Bsize)
  15. disk.Free = fs.Bfree * uint64(fs.Bsize)
  16. disk.Used = disk.All - disk.Free
  17. disk.PercentFree = float32((float64(disk.Free) / float64(disk.All)) * 100)
  18. disk.PercentUsed = float32((float64(disk.Used) / float64(disk.All)) * 100)
  19. return
  20. }