server+healthcheck: rename function, add absolute disk space function

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.
This commit is contained in:
Oliver Gugger committed 2020-11-13 10:19:50 +01:00
1 parent f8907fdb47
commit 35c1fad517
6 files changed
+83 -16

No files matched your search

+15 -3
View File
@@ -2,9 +2,9 @@ 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) {
// AvailableDiskSpaceRatio returns ratio of available disk space to total
// capacity for openbsd.
func AvailableDiskSpaceRatio(path string) (float64, error) {
s := unix.Statfs_t{}
err := unix.Statfs(path, &s)
if err != nil {
@@ -15,3 +15,15 @@ func AvailableDiskSpace(path string) (float64, error) {
// free blocks.
return float64(s.F_bfree) / float64(s.F_blocks), nil
}
// AvailableDiskSpace returns the available disk space in bytes of the given
// file system for openbsd.
func AvailableDiskSpace(path string) (uint64, error) {
s := unix.Statfs_t{}
err := unix.Statfs(path, &s)
if err != nil {
return 0, err
}
return uint64(s.F_bavail) * uint64(s.F_bsize), nil
}