diff --git a/internal/system_check/linux_ram.go b/internal/system_check/linux_ram.go index f004788..d0465a6 100644 --- a/internal/system_check/linux_ram.go +++ b/internal/system_check/linux_ram.go @@ -18,35 +18,40 @@ func getLinuxRamInfo() (MemoryInformation, error) { if err != nil { return MemoryInformation{}, fmt.Errorf("Could not find /proc/meminfo. Are you sure you are on linux?") } + defer memoryFile.Close() + fileReader := bufio.NewScanner(memoryFile) var TotalMemory uint64 var AvailMemory uint64 for fileReader.Scan() { - - if fileReader.Err() != nil { - return MemoryInformation{}, fmt.Errorf("There was an error while reading /proc/meninfo. Error: %v", fileReader.Err()) - } - line := fileReader.Text() - if strings.Contains(line, "MemTotal") { + if strings.HasPrefix(line, "MemTotal:") { TotalMemory, err = strconv.ParseUint(numberRegex.FindString(line), 10, 64) if err != nil { return MemoryInformation{}, fmt.Errorf("Could not parse total memory from /proc/meminfo") } - } else if strings.Contains(line, "MemAvailable") { + } else if strings.HasPrefix(line, "MemAvailable:") { AvailMemory, err = strconv.ParseUint(numberRegex.FindString(line), 10, 64) if err != nil { return MemoryInformation{}, fmt.Errorf("Could not parse available memory from /proc/meminfo") } } + + if TotalMemory > 0 && AvailMemory > 0 { + break + } + } + + if fileReader.Err() != nil { + return MemoryInformation{}, fmt.Errorf("There was an error while reading /proc/meninfo. Error: %v", fileReader.Err()) } return MemoryInformation{ - SystemMemory: TotalMemory, - AvailableMemory: AvailMemory, + SystemMemory: TotalMemory * 1024, + AvailableMemory: AvailMemory * 1024, }, nil }