Files
Hightube/backend/internal/monitor/disk_linux.go

29 lines
469 B
Go

//go:build linux
package monitor
import (
"os"
"syscall"
)
func getDiskSpaceGB() (float64, float64) {
wd, err := os.Getwd()
if err != nil {
return 0, 0
}
var stat syscall.Statfs_t
if err := syscall.Statfs(wd, &stat); err != nil {
return 0, 0
}
const gb = 1024.0 * 1024.0 * 1024.0
blockSize := uint64(stat.Bsize)
totalBytes := stat.Blocks * blockSize
freeBytes := stat.Bfree * blockSize
return float64(totalBytes) / gb, float64(freeBytes) / gb
}