mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
Extends the disk space monitoring functionality by adding support for retrieving total disk capacity in addition to free space. Related: https://github.com/VictoriaMetrics/VictoriaLogs/issues/513 --------- Co-authored-by: Hanzo Dev <[email protected]>
23 lines
478 B
Go
23 lines
478 B
Go
//go:build linux || darwin || freebsd
|
|
|
|
package fs
|
|
|
|
import (
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
type statfs_t = unix.Statfs_t
|
|
|
|
func freeSpace(stat statfs_t) uint64 {
|
|
return uint64(stat.Bavail) * uint64(stat.Bsize)
|
|
}
|
|
|
|
// totalSpace returns the total capacity of the filesystem described by stat in bytes.
|
|
func totalSpace(stat statfs_t) uint64 {
|
|
return uint64(stat.Blocks) * uint64(stat.Bsize)
|
|
}
|
|
|
|
func statfs(path string, stat *statfs_t) (err error) {
|
|
return unix.Statfs(path, stat)
|
|
}
|