diff --git a/healthcheck/diskcheck.go b/healthcheck/diskcheck.go index c3e2cbb2..ed230d27 100644 --- a/healthcheck/diskcheck.go +++ b/healthcheck/diskcheck.go @@ -1,4 +1,4 @@ -// +build !windows,!solaris +// +build !windows,!solaris,!netbsd,!openbsd package healthcheck diff --git a/healthcheck/diskcheck_netbsd.go b/healthcheck/diskcheck_netbsd.go new file mode 100644 index 00000000..d44330b7 --- /dev/null +++ b/healthcheck/diskcheck_netbsd.go @@ -0,0 +1,17 @@ +package healthcheck + +import "golang.org/x/sys/unix" + +// AvailableDiskSpace returns ratio of available disk space to total capacity +// for solaris. +func AvailableDiskSpace(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 +} diff --git a/healthcheck/diskcheck_openbsd.go b/healthcheck/diskcheck_openbsd.go new file mode 100644 index 00000000..4738db9a --- /dev/null +++ b/healthcheck/diskcheck_openbsd.go @@ -0,0 +1,17 @@ +package healthcheck + +import "golang.org/x/sys/unix" + +// AvailableDiskSpace returns ratio of available disk space to total capacity +// for solaris. +func AvailableDiskSpace(path string) (float64, error) { + s := unix.Statfs_t{} + err := unix.Statfs(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.F_bfree) / float64(s.F_blocks), nil +}