github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/util/disk/usage_unix.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package disk 5 6 import ( 7 "syscall" 8 9 "github.com/pyroscope-io/pyroscope/pkg/util/bytesize" 10 ) 11 12 func Usage(path string) (UsageStats, error) { 13 var fs syscall.Statfs_t 14 if err := syscall.Statfs(path, &fs); err != nil { 15 return UsageStats{}, err 16 } 17 u := UsageStats{ 18 Total: bytesize.ByteSize(fs.Blocks) * bytesize.ByteSize(fs.Bsize), 19 Available: bytesize.ByteSize(fs.Bavail) * bytesize.ByteSize(fs.Bsize), 20 } 21 return u, nil 22 }