FALCON / internal /protocol /telemetry_linux.go
st3v3x's picture
Actualizar nodo OmniVision
d9a1d72 verified
Raw History Blame Contribute Delete
633 Bytes
//go:build linux
package protocol
import "syscall"
func collectDiskUsage() (usedMB, totalMB int64, percent float64) {
var stat syscall.Statfs_t
if err := syscall.Statfs("/", &stat); err != nil {
if err := syscall.Statfs(".", &stat); err != nil {
return 0, 0, 0
}
}
totalBytes := stat.Blocks * uint64(stat.Bsize)
freeBytes := stat.Bavail * uint64(stat.Bsize)
if totalBytes == 0 {
return 0, 0, 0
}
usedBytes := totalBytes - freeBytes
totalMB = int64(totalBytes / (1024 * 1024))
usedMB = int64(usedBytes / (1024 * 1024))
percent = float64(usedBytes) * 100 / float64(totalBytes)
return usedMB, totalMB, percent
}