luci-mod-admin-full: eliminate the use of luci.sys.sysinfo()

Fetch the required information via ubus instead of relying on the
to-be-removed luci.sys.sysinfo() and luci.sys.loadavg() functions.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
Jo-Philipp Wich 2015-01-15 13:35:10 +01:00
parent 0b491a05ca
commit 46beca9fb1

View file

@ -19,11 +19,22 @@ You may obtain a copy of the License at
local has_dhcp = luci.fs.access("/etc/config/dhcp") local has_dhcp = luci.fs.access("/etc/config/dhcp")
local has_wifi = luci.fs.stat("/etc/config/wireless") local has_wifi = luci.fs.stat("/etc/config/wireless")
has_wifi = has_wifi and has_wifi.size > 0 has_wifi = has_wifi and has_wifi.size > 0
local _, _, memtotal, memcached, membuffers, memfree, _, swaptotal, swapcached, swapfree = luci.sys.sysinfo()
local has_swap local sysinfo = luci.util.ubus("system", "info") or { }
if swaptotal > 0 then local boardinfo = luci.util.ubus("system", "board") or { }
has_swap = 1
end local meminfo = sysinfo.memory or {
total = 0,
free = 0,
buffered = 0,
shared = 0
}
local swapinfo = sysinfo.swap or {
total = 0,
free = 0
}
local has_dsl = luci.fs.stat("/etc/init.d/dsl_control") local has_dsl = luci.fs.stat("/etc/init.d/dsl_control")
if luci.http.formvalue("status") == "1" then if luci.http.formvalue("status") == "1" then
@ -42,16 +53,11 @@ You may obtain a copy of the License at
""):match("%d+")) or 4096 ""):match("%d+")) or 4096
local rv = { local rv = {
uptime = luci.sys.uptime(), uptime = sysinfo.uptime or 0,
localtime = os.date(), localtime = sysinfo.localtime or 0,
loadavg = { luci.sys.loadavg() }, loadavg = sysinfo.load or { 0, 0, 0 },
memtotal = memtotal, memory = meminfo,
memcached = memcached, swap = swapinfo,
membuffers = membuffers,
memfree = memfree,
swaptotal = swaptotal,
swapcached = swapcached,
swapfree = swapfree,
connmax = conn_max, connmax = conn_max,
conncount = conn_count, conncount = conn_count,
leases = luci.tools.status.dhcp_leases(), leases = luci.tools.status.dhcp_leases(),
@ -95,8 +101,6 @@ You may obtain a copy of the License at
return return
end end
local system, model = luci.sys.sysinfo()
-%> -%>
<%+header%> <%+header%>
@ -501,50 +505,47 @@ You may obtain a copy of the License at
var e; var e;
if (e = document.getElementById('localtime')) if (e = document.getElementById('localtime'))
e.innerHTML = info.localtime; e.innerHTML = (new Date(info.localtime * 1000)).toUTCString();
if (e = document.getElementById('uptime')) if (e = document.getElementById('uptime'))
e.innerHTML = String.format('%t', info.uptime); e.innerHTML = String.format('%t', info.uptime);
if (e = document.getElementById('loadavg')) if (e = document.getElementById('loadavg'))
e.innerHTML = String.format('%.02f, %.02f, %.02f', e.innerHTML = String.format(
info.loadavg[0], info.loadavg[1], info.loadavg[2]); '%.02f, %.02f, %.02f',
info.loadavg[0] / 65535.0,
info.loadavg[1] / 65535.0,
info.loadavg[2] / 65535.0
);
if (e = document.getElementById('memtotal')) if (e = document.getElementById('memtotal'))
e.innerHTML = progressbar( e.innerHTML = progressbar(
(info.memfree + info.membuffers + info.memcached) + " <%:kB%>", ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
info.memtotal + " <%:kB%>" (info.memory.total / 1024) + " <%:kB%>"
); );
if (e = document.getElementById('memfree')) if (e = document.getElementById('memfree'))
e.innerHTML = progressbar( e.innerHTML = progressbar(
info.memfree + " <%:kB%>", info.memtotal + " <%:kB%>" (info.memory.free / 1024) + " <%:kB%>",
); (info.memory.total / 1024) + " <%:kB%>"
if (e = document.getElementById('memcache'))
e.innerHTML = progressbar(
info.memcached + " <%:kB%>", info.memtotal + " <%:kB%>"
); );
if (e = document.getElementById('membuff')) if (e = document.getElementById('membuff'))
e.innerHTML = progressbar( e.innerHTML = progressbar(
info.membuffers + " <%:kB%>", info.memtotal + " <%:kB%>" (info.memory.buffered / 1024) + " <%:kB%>",
); (info.memory.total / 1024) + " <%:kB%>"
if (e = document.getElementById('swapcache'))
e.innerHTML = progressbar(
info.swapcached + " <%:kB%>", info.swaptotal + " <%:kB%>"
); );
if (e = document.getElementById('swaptotal')) if (e = document.getElementById('swaptotal'))
e.innerHTML = progressbar( e.innerHTML = progressbar(
(info.swapfree + info.swapcached) + " <%:kB%>", (info.swap.free / 1024) + " <%:kB%>",
info.swaptotal + " <%:kB%>" (info.swap.total / 1024) + " <%:kB%>"
); );
if (e = document.getElementById('swapfree')) if (e = document.getElementById('swapfree'))
e.innerHTML = progressbar( e.innerHTML = progressbar(
info.swapfree + " <%:kB%>", info.swaptotal + " <%:kB%>" (info.swap.free / 1024) + " <%:kB%>",
(info.swap.total / 1024) + " <%:kB%>"
); );
if (e = document.getElementById('conns')) if (e = document.getElementById('conns'))
@ -561,7 +562,7 @@ You may obtain a copy of the License at
<table width="100%" cellspacing="10"> <table width="100%" cellspacing="10">
<tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr> <tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
<tr><td width="33%"><%:Model%></td><td><%=pcdata(model or "?")%></td></tr> <tr><td width="33%"><%:Model%></td><td><%=pcdata(boardinfo.model or boardinfo.system or "?")%></td></tr>
<tr><td width="33%"><%:Firmware Version%></td><td> <tr><td width="33%"><%:Firmware Version%></td><td>
<%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> / <%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> /
<%=pcdata(luci.version.luciname)%> (<%=pcdata(luci.version.luciversion)%>) <%=pcdata(luci.version.luciname)%> (<%=pcdata(luci.version.luciversion)%>)
@ -579,19 +580,17 @@ You may obtain a copy of the License at
<table width="100%" cellspacing="10"> <table width="100%" cellspacing="10">
<tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr> <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
<tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr> <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
<tr><td width="33%"><%:Cached%></td><td id="memcache">-</td></tr>
<tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr> <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
</table> </table>
</fieldset> </fieldset>
<% if has_swap then %> <% if swapinfo.total > 0 then %>
<fieldset class="cbi-section"> <fieldset class="cbi-section">
<legend><%:Swap%></legend> <legend><%:Swap%></legend>
<table width="100%" cellspacing="10"> <table width="100%" cellspacing="10">
<tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr> <tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr>
<tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr> <tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr>
<tr><td width="33%"><%:Cached%></td><td id="swapcache">-</td></tr>
</table> </table>
</fieldset> </fieldset>
<% end %> <% end %>