//go:build linux package main import ( "bufio" "os" "strconv" "strings" ) // hostMemory devuelve memoria disponible y total del host en bytes. func hostMemory() (avail, total uint64, ok bool) { f, err := os.Open("/proc/meminfo") if err != nil { return 0, 0, false } defer f.Close() sc := bufio.NewScanner(f) for sc.Scan() { fields := strings.Fields(sc.Text()) if len(fields) < 2 { continue } v, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } switch fields[0] { case "MemTotal:": total = v * 1024 case "MemAvailable:": avail = v * 1024 } } return avail, total, total > 0 && avail > 0 }