Skip to content

Commit 83ec274

Browse files
authored
Gui: Display Used memory instead of Free RAM memory (#1045)
* gui: show used/total RAM instead of free/total (1/2) Viewing the free memory is useless as that's simply unused portion of memory and it can easily drop under 10MB freaking the user. Total-Used=Available , which includes free memory but also includes stuff like Buffered/Cached memory which is dynamically managed to fit the bill. I opted for showing Used / Total to respect the logic of the surrounding elements: numbers grow as resources consumption grows, but one can prefer Available / Total which is imply subtracting the two as I mentioned previously. * gui: show used/total RAM instead of free/total (2/2) * trafficmon: use MemAvailable instead of MemFree [ci skip]
1 parent 0e5abd6 commit 83ec274

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

decompressed/gui_file/www/docroot/ajax/cpuload.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ local readfile = require("web.content_helper").readfile
44
local post_helper = require("web.post_helper")
55
local ngx = ngx
66

7-
local ram = tonumber(proxy.get("sys.mem.RAMFree")[1].value or 0) or 0
7+
local ram = tonumber(proxy.get("sys.mem.RAMUsed")[1].value or 0) or 0
88
local cpu_usage = proxy.get("sys.proc.CPUUsage")[1].value or "0"
99

1010
local data = {
1111
cpuusage = cpu_usage .. "%" or "0",
12-
ram_free = math.floor(ram / 1024),
12+
ram_used = math.floor(ram / 1024),
1313
uptime = post_helper.secondsToTime(readfile("/proc/uptime","number",floor)),
1414
connection = readfile("/proc/sys/net/netfilter/nf_conntrack_count"),
1515
system_time = os.date("%d/%m/%Y %Hh:%Mm:%Ss",os.time()),

decompressed/gui_file/www/info-cards/001_gateway.lp

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ local content = {
1919
firmware_version = "uci.env.var.friendly_sw_version_activebank",
2020
gui_version = "rpc.system.modgui.gui_version",
2121
cpuusage = "sys.proc.CPUUsage",
22-
ram_free = "sys.mem.RAMFree",
22+
ram_used = "sys.mem.RAMUsed",
2323
ram_total = "sys.mem.RAMTotal",
2424
outdated_ver = "uci.modgui.gui.outdated_ver",
2525
}
2626

2727
content_helper.getExactContent(content)
2828

29-
content["ram_free"] = math.floor(tonumber(content["ram_free"]) / 1024)
29+
content["ram_used"] = math.floor(tonumber(content["ram_used"]) / 1024)
3030
content["ram_total"] = math.floor(tonumber(content["ram_total"]) / 1024)
3131

3232
if content.outdated_ver == "1" then
@@ -97,10 +97,10 @@ nf_conntrack_count:close()
9797
basic.span["data-bind"] = "text: cpuusage"
9898
html[#html + 1] = ui_helper.createLabel(T"CPU Usage", content["cpuusage"] .. "%", basic)
9999
html[#html + 1] = '<div class="control-group">'
100-
html[#html + 1] = '<label class="control-label">' .. T("Free Memory") .. '</label>'
100+
html[#html + 1] = '<label class="control-label">' .. T("RAM Usage") .. '</label>'
101101
html[#html + 1] = '<div class="controls">'
102102
html[#html + 1] = '<span id="Ram" class=" simple-desc span3">'
103-
html[#html + 1] = format('<span data-bind="text: ram_free">%s</span>',content["ram_free"])
103+
html[#html + 1] = format('<span data-bind="text: ram_used">%s</span>',content["ram_used"])
104104
html[#html + 1] = format(' / %s MB', content["ram_total"])
105105
html[#html + 1] = '</span>'
106106
html[#html + 1] = '</div>'

decompressed/traffic_mon/sbin/trafficmon.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ local function getMemFree()
3434
local f = io.open("/proc/meminfo","r")
3535
if f then
3636
for line in f:lines() do
37-
if line:match("MemFree") then
38-
ret = line:gsub("MemFree:%s*",""):gsub("[A-z]+%s*","")
37+
if line:match("MemAvailable") then
38+
ret = line:gsub("MemAvailable:%s*",""):gsub("[A-z]+%s*","")
3939
break
4040
end
4141
end

0 commit comments

Comments
 (0)