package health import ( "path/filepath" "runtime" ) // fsKey uniquely identifies a mounted filesystem (dedupe across scan roots). type fsKey struct { typ int64 val0 int32 val1 int32 } type Snapshot struct { UptimeSeconds int64 CPUUsagePercent float64 MemoryUsagePercent float64 StorageTotalBytes uint64 StorageFreeBytes uint64 LibraryFileCount int ActiveStreams int CurrentBytesPerSec int64 ScanStatus string Errors []string } func MemoryUsagePercent() float64 { var m runtime.MemStats runtime.ReadMemStats(&m) if m.Sys == 0 { return 0 } return float64(m.Alloc) / float64(m.Sys) * 100 } func DiskUsage(paths []string) (total, free uint64) { seenPaths := map[string]bool{} seenFS := map[fsKey]bool{} for _, p := range paths { if p == "" { continue } key := filepath.Clean(p) if seenPaths[key] { continue } seenPaths[key] = true t, f, fsid, ok := diskStat(p) if !ok { continue } if seenFS[fsid] { continue } seenFS[fsid] = true total += t free += f } return total, free }