From d4825ff7b3c0440055dda617def31fdcc7dd55dd Mon Sep 17 00:00:00 2001 From: Lauri Nomme Date: Mon, 22 Jul 2019 17:35:44 +0300 Subject: [PATCH] Workaround for memory size as non-root user --- memory.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/memory.go b/memory.go index b5ab7bd..2373a86 100644 --- a/memory.go +++ b/memory.go @@ -158,6 +158,13 @@ func (si *SysInfo) getMemoryInfo() { si.Memory.Type = "DRAM" size, _ := strconv.ParseUint(targetKB, 10, 64) si.Memory.Size = uint(size) / 1024 + } else if meminfo := slurpFile("/proc/meminfo"); meminfo != "" && strings.HasPrefix(meminfo, "MemTotal:") { + si.Memory.Type = "DRAM" + lines := strings.Split(meminfo, "\n") + memTotalLine := lines[0] + parts := strings.Split(strings.TrimSpace(memTotalLine[9:]), " ") + size, _ := strconv.ParseUint(parts[0], 10, 64) + si.Memory.Size = uint(size) / 1024 } return }