stremio/node/media-node/internal/health/health.go
Jos Vooges | STH 106aa996a4 Fix storage double-count, add incremental catch-up scan, improve 4K detection.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-27 07:39:43 +02:00

54 lines
944 B
Go

package health
import (
"path/filepath"
"runtime"
)
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
}