From 5af8824823fdef12b1c12158e73d0be6020a7d95 Mon Sep 17 00:00:00 2001 From: Raymundo Cassani Date: Tue, 2 Jun 2020 11:14:32 -0400 Subject: [PATCH] Update RAM calculation. Used = Total - Available, and presented in GiB --- files/system-monitor-graph@rcassani/desklet.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/files/system-monitor-graph@rcassani/desklet.js b/files/system-monitor-graph@rcassani/desklet.js index 858ed54..dc5bd70 100644 --- a/files/system-monitor-graph@rcassani/desklet.js +++ b/files/system-monitor-graph@rcassani/desklet.js @@ -11,7 +11,8 @@ const Util = imports.misc.util; const UUID = "system-monitor-graph@rcassani"; const DESKLET_PATH = imports.ui.deskletManager.deskletMeta[UUID].path; -const GB_TO_KB = 1048576; // 1 GB = 1,048,576 kB +const GIB_TO_KIB = 1048576; // 1 GiB = 1,048,576 kiB +const GB_TO_KB = 1000000; // 1 GB = 1,000,000 kB function MyDesklet(metadata, desklet_id) { @@ -138,7 +139,7 @@ MyDesklet.prototype = { text1 = "RAM"; text2 = Math.round(ram_use).toString() + "%" text3 = ram_values[1].toFixed(1) + " / " - + ram_values[0].toFixed(1) + " GB"; + + ram_values[0].toFixed(1) + " GiB"; break; case "hdd": @@ -270,16 +271,13 @@ MyDesklet.prototype = { }, get_ram_values: function() { - // https://www.man7.org/linux/man-pages/man1/free.1.html + // used = total - available let mem_out = Cinnamon.get_file_contents_utf8_sync("/proc/meminfo"); let mem_tot = parseInt(mem_out.match(/(MemTotal):\D+(\d+)/)[2]); - let mem_usd = mem_tot - parseInt(mem_out.match(/(MemFree):\D+(\d+)/)[2]) - - parseInt(mem_out.match(/(Cached):\D+(\d+)/)[2]) - - parseInt(mem_out.match(/(Buffers):\D+(\d+)/)[2]) - - parseInt(mem_out.match(/(SReclaimable):\D+(\d+)/)[2]); + let mem_usd = mem_tot - parseInt(mem_out.match(/(MemAvailable):\D+(\d+)/)[2]); - let ram_tot = mem_tot / GB_TO_KB; - let ram_usd = mem_usd / GB_TO_KB; + let ram_tot = mem_tot / GIB_TO_KIB; + let ram_usd = mem_usd / GIB_TO_KIB; return [ram_tot, ram_usd]; },