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:
28
backend/internal/monitor/disk_linux.go
Normal file
28
backend/internal/monitor/disk_linux.go
Normal 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
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows
|
||||
//go:build !windows && !linux
|
||||
|
||||
package monitor
|
||||
|
||||
|
||||
Reference in New Issue
Block a user