From ae3825387bd9b47813e0b862db38959e7000cb02 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 28 Nov 2010 06:41:45 +0000 Subject: modules/admin-full: add SVG based realtime bandwidth status --- .../admin-full/luasrc/controller/admin/status.lua | 31 +++ .../luasrc/view/admin_status/bandwidth.htm | 310 +++++++++++++++++++++ 2 files changed, 341 insertions(+) create mode 100644 modules/admin-full/luasrc/view/admin_status/bandwidth.htm (limited to 'modules/admin-full/luasrc') diff --git a/modules/admin-full/luasrc/controller/admin/status.lua b/modules/admin-full/luasrc/controller/admin/status.lua index 55bba2f381..d283627ebf 100644 --- a/modules/admin-full/luasrc/controller/admin/status.lua +++ b/modules/admin-full/luasrc/controller/admin/status.lua @@ -25,6 +25,9 @@ function index() entry({"admin", "status", "syslog"}, call("action_syslog"), i18n("System Log"), 5) entry({"admin", "status", "dmesg"}, call("action_dmesg"), i18n("Kernel Log"), 6) + entry({"admin", "status", "bandwidth"}, template("admin_status/bandwidth"), i18n("Realtime Traffic"), 7).leaf = true + entry({"admin", "status", "bandwidth_status"}, call("action_bandwidth")).leaf = true + end function action_syslog() @@ -52,3 +55,31 @@ function action_iptables() luci.template.render("admin_status/iptables") end end + +function action_bandwidth() + local path = luci.dispatcher.context.requestpath + local iface = path[#path] + + local fs = require "luci.fs" + if fs.access("/var/lib/luci-bwc/%s" % iface) then + luci.http.prepare_content("application/json") + + local bwc = io.popen("luci-bwc -p %q 2>/dev/null" % iface) + if bwc then + luci.http.write("[") + + while true do + local ln = bwc:read("*l") + if not ln then break end + luci.http.write(ln) + end + + luci.http.write("]") + bwc:close() + end + + return + end + + luci.http.status(404, "No such interface") +end diff --git a/modules/admin-full/luasrc/view/admin_status/bandwidth.htm b/modules/admin-full/luasrc/view/admin_status/bandwidth.htm new file mode 100644 index 0000000000..f12a222511 --- /dev/null +++ b/modules/admin-full/luasrc/view/admin_status/bandwidth.htm @@ -0,0 +1,310 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2010 Jo-Philipp Wich + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +-%> + +<%- + local dev + local devices = { } + for _, dev in luci.util.kspairs(luci.sys.net.devices()) do + if dev ~= "lo" then + devices[#devices+1] = dev + end + end + + local curdev = luci.dispatcher.context.requestpath + curdev = curdev[#curdev] ~= "bandwidth" and curdev[#curdev] or devices[1] +-%> + +<%+header%> + + + + +

<%:Realtime Traffic%>

+ + + + +
-
+
+ + + + + + + + + + + + + + + + + + + + + + +
<%:Inbound:%>0 kbit/s
(0 KB/s)
<%:Average:%>0 kbit/s
(0 KB/s)
<%:Peak:%>0 kbit/s
(0 KB/s)
<%:Outbound:%>0 kbit/s
(0 KB/s)
<%:Average:%>0 kbit/s
(0 KB/s)
<%:Peak:%>0 kbit/s
(0 KB/s)
+ + +

+
+
+<%+footer%>
-- 
cgit v1.2.3