From 64d0031233a7e1b7e4df71953bc0fa72462e6bf5 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 15 Jan 2015 14:11:35 +0100 Subject: [PATCH] luci-mod-freifunk: eliminate uses of luci.sys.sysinfo() Signed-off-by: Jo-Philipp Wich --- .../luasrc/controller/freifunk/freifunk.lua | 36 ++++++++++++++-- .../luasrc/view/freifunk/public_status.htm | 42 ++++++++++--------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/modules/luci-mod-freifunk/luasrc/controller/freifunk/freifunk.lua b/modules/luci-mod-freifunk/luasrc/controller/freifunk/freifunk.lua index d4606e750f..bb58a3f10f 100644 --- a/modules/luci-mod-freifunk/luasrc/controller/freifunk/freifunk.lua +++ b/modules/luci-mod-freifunk/luasrc/controller/freifunk/freifunk.lua @@ -139,14 +139,42 @@ function jsonstatus() local ffznet = ffzone and cursor:get("firewall", ffzone, "network") local ffwifs = ffznet and util.split(ffznet, " ") or {} + local sysinfo = util.ubus("system", "info") or { } + local boardinfo = util.ubus("system", "board") or { } + + local loads = sysinfo.load or { 0, 0, 0 } + + local memory = sysinfo.memory or { + total = 0, + free = 0, + shared = 0, + buffered = 0 + } + + local swap = sysinfo.swap or { + total = 0, + free = 0 + } + root.protocol = 1 root.system = { - uptime = {sys.uptime()}, - loadavg = {sys.loadavg()}, - sysinfo = {sys.sysinfo()}, - hostname = sys.hostname() + uptime = { sysinfo.uptime or 0 }, + loadavg = { loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0 }, + sysinfo = { + boardinfo.system or "?", + boardinfo.model or "?", + memory.total, + 0, -- former cached memory + memory.buffered, + memory.free, + 0, -- former bogomips + swap.total, + 0, -- former cached swap + swap.free + }, + hostname = boardinfo.hostname } root.firmware = { diff --git a/modules/luci-mod-freifunk/luasrc/view/freifunk/public_status.htm b/modules/luci-mod-freifunk/luasrc/view/freifunk/public_status.htm index 10bd849d7d..715ac756fd 100644 --- a/modules/luci-mod-freifunk/luasrc/view/freifunk/public_status.htm +++ b/modules/luci-mod-freifunk/luasrc/view/freifunk/public_status.htm @@ -1,33 +1,37 @@ <% +local utl = require "luci.util" local sys = require "luci.sys" local twa = require "luci.tools.webadmin" -- System -local model, system, memtotal, memcached, membuffers, memfree, bogomips = sys.sysinfo() -local uptime = twa.date_format(tonumber(sys.uptime())) + +local sysinfo = utl.ubus("system", "info") or { } +local boardinfo = utl.ubus("system", "board") or { } + +local loads = sysinfo.load or { 0, 0, 0 } +local meminfo = sysinfo.memory or { + total = 0, + free = 0, + buffered = 0, + shared = 0 +} + +local uptime = twa.date_format(sysinfo.uptime or 0) local time = os.date("%a, %d %b %Y, %H:%M:%S") -local load1, load5, load15 = sys.loadavg() -local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15) +local load = string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0) local mem = string.format( - "%.2f MB (%.2f %s, %.2f %s, %.2f %s, %.2f %s)", - tonumber(memtotal) / 1024, - tonumber(memtotal - memfree) / 1024, + "%.2f MB (%.2f %s, %.2f %s, %.2f %s)", + memory.total / 1024 / 1024, + (memory.total - memory.free) / 1024 / 1024, tostring(i18n.translate("used")), - memfree / 1024, + memory.free / 1024 / 1024, tostring(i18n.translate("free")), - memcached / 1024, - tostring(i18n.translate("cached")), - membuffers / 1024, + memory.buffered / 1024 / 1024, tostring(i18n.translate("buffered")) ) --- update interval -local bogomips = bogomips or 100 -local interval = 10 -if bogomips > 350 then - interval = 5 -end +local interval = 5 -- wireless local ntm = require "luci.model.network".init() @@ -230,8 +234,8 @@ end

<%:System%>

-
<%=system%>
-
<%=model%>
+
<%=boardinfo.system or "?"%>
+
<%=boardinfo.model or "?"%>
<%=load%>
<%=mem%>
<%=time%>
-- 2.30.2