From 93ec94b40eee6a94f004ba165b878723d954a570 Mon Sep 17 00:00:00 2001 From: "Juan Perdomo [Jakepy]" Date: Fri, 12 Jun 2026 18:25:12 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20add=20dynamic=20RAM=20unit=20detection?= =?UTF-8?q?=20and=20fix=20file=20descriptor=20leaks=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/providers/systemstats.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/providers/systemstats.go b/src/providers/systemstats.go index f6b21f1..cf63c75 100644 --- a/src/providers/systemstats.go +++ b/src/providers/systemstats.go @@ -45,13 +45,32 @@ func GetDist() (string, string) { return id, prettyName } +func getSizeRam(total, avaible, used *int) string { + if *total >= 1024*1024 && *avaible >= 1024*1024 { + *used = *total - *avaible + usedGiB := *used / (1024 * 1024) + totalGiB := *total / (1024 * 1024) + ram := fmt.Sprintf("%d / %d Gi", usedGiB, totalGiB) + ram = strings.TrimSpace(ram) + return ram + + } + + totalMB := *total / 1024 + avaibleMB := *avaible / 1024 + *used = totalMB - avaibleMB + return fmt.Sprintf("%d / %d MiB", *used, totalMB) +} + func GetRam() string { f, err := os.Open("/proc/meminfo") if err != nil { return "error" } - var total, available int + defer f.Close() + + var total, available, used int s := bufio.NewScanner(f) for s.Scan() { line := s.Text() @@ -68,11 +87,8 @@ func GetRam() string { } } } - totalMB := total / 1024 - availableMB := available / 1024 - usedMB := totalMB - availableMB - ram := fmt.Sprintf("%d / %d MiB", usedMB, totalMB) + ram := getSizeRam(&total, &available, &used) ram = strings.TrimSpace(ram) return ram @@ -84,6 +100,8 @@ func GetCpu() string { return "unknown" } + defer f.Close() + var cpu string s := bufio.NewScanner(f) for s.Scan() {