Merge pull request #4618 from Roasbeef/healthcheck-bsd

healtcheck: add extra build tags+files for netbsd and openbsd
This commit is contained in:
Olaoluwa Osuntokun 2020-09-15 18:54:02 -07:00 committed by GitHub
commit 9dcb522ebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -1,4 +1,4 @@
// +build !windows,!solaris
// +build !windows,!solaris,!netbsd,!openbsd
package healthcheck

View File

@ -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
}

View File

@ -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
}