35c1fad517
With this commit we rename the existing AvailableDiskSpace function to its correct name AvailableDiskSpaceRatio as it only returns a ratio. We then go ahead and add a new function that returns the actual number of free bytes available on a file system. This also fixes some comments and always returns an error instead of panicking.
30 lines
736 B
Go
30 lines
736 B
Go
package healthcheck
|
|
|
|
import "golang.org/x/sys/unix"
|
|
|
|
// AvailableDiskSpaceRatio returns ratio of available disk space to total
|
|
// capacity for solaris.
|
|
func AvailableDiskSpaceRatio(path string) (float64, error) {
|
|
s := unix.Statvfs_t{}
|
|
err := unix.Statvfs(path, &s)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
// Calculate our free blocks/total blocks to get our total ratio of
|
|
// free blocks.
|
|
return float64(s.Bfree) / float64(s.Blocks), nil
|
|
}
|
|
|
|
// AvailableDiskSpace returns the available disk space in bytes of the given
|
|
// file system for solaris.
|
|
func AvailableDiskSpace(path string) (uint64, error) {
|
|
s := unix.Statvfs_t{}
|
|
err := unix.Statvfs(path, &s)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return s.Bavail * uint64(s.Bsize), nil
|
|
}
|