feat: add Linux disk space monitoring support- add disk_linux.go using syscall.Statfs to retrieve disk info- update disk_other.go build tag to exclude both Windows and Linux

This commit is contained in:
Z
2026-06-27 14:58:55 +08:00
parent b0e3d6069a
commit 804adf94a3
2 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
//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
}

View File

@@ -1,4 +1,4 @@
//go:build !windows
//go:build !windows && !linux
package monitor