function index()
- require("luci.fs")
+ require("nixio.fs")
require("luci.util")
- require("luci.i18n")
require("luci.statistics.datatree")
- -- load language files
- luci.i18n.loadc("rrdtool")
- luci.i18n.loadc("statistics")
-
-- get rrd data tree
local tree = luci.statistics.datatree.Instance()
-- override entry(): check for existance <plugin>.so where <plugin> is derived from the called path
function _entry( path, ... )
local file = path[5] or path[4]
- if luci.fs.isfile( "/usr/lib/collectd/" .. file .. ".so" ) then
+ if nixio.fs.access( "/usr/lib/collectd/" .. file .. ".so" ) then
entry( path, ... )
end
end
- -- override i18n(): try to translate stat_<str> or fall back to <str>
- function _i18n( str )
- return luci.i18n.translate( "stat_" .. str, str )
- end
+ local labels = {
+ s_output = _("Output plugins"),
+ s_system = _("System plugins"),
+ s_network = _("Network plugins"),
+
+ rrdtool = _("RRDTool"),
+ network = _("Network"),
+ unixsock = _("UnixSock"),
+ csv = _("CSV Output"),
+ exec = _("Exec"),
+ email = _("Email"),
+ cpu = _("Processor"),
+ df = _("Disk Space Usage"),
+ disk = _("Disk Usage"),
+ irq = _("Interrupts"),
+ processes = _("Processes"),
+ load = _("System Load"),
+ interface = _("Interfaces"),
+ netlink = _("Netlink"),
+ iptables = _("Firewall"),
+ tcpconns = _("TCP Connections"),
+ ping = _("Ping"),
+ dns = _("DNS"),
+ wireless = _("Wireless")
+ }
-- our collectd menu
local collectd_menu = {
}
-- create toplevel menu nodes
- entry({"admin", "statistics"}, call("statistics_index"), _i18n("statistics"), 80).i18n = "statistics"
- entry({"admin", "statistics", "collectd"}, cbi("luci_statistics/collectd"), _i18n("collectd"), 10)
+ local st = entry({"admin", "statistics"}, template("admin_statistics/index"), _("Statistics"), 80)
+ st.i18n = "statistics"
+ st.index = true
+
+ entry({"admin", "statistics", "collectd"}, cbi("luci_statistics/collectd"), _("Collectd"), 10).subindex = true
+
-- populate collectd plugin menu
local index = 1
for section, plugins in luci.util.kspairs( collectd_menu ) do
- entry(
+ local e = entry(
{ "admin", "statistics", "collectd", section },
call( "statistics_" .. section .. "plugins" ),
- _i18n( section .. "plugins" ),
- index * 10
+ labels["s_"..section], index * 10
)
+ e.index = true
+ e.i18n = "rrdtool"
+
for j, plugin in luci.util.vspairs( plugins ) do
_entry(
{ "admin", "statistics", "collectd", section, plugin },
cbi("luci_statistics/" .. plugin ),
- _i18n( plugin ),
- j * 10
+ labels[plugin], j * 10
)
end
end
-- output views
- local page = entry( { "admin", "statistics", "graph" }, call("statistics_index"), _i18n("graphs"), 80)
+ local page = entry( { "admin", "statistics", "graph" }, template("admin_statistics/index"), _("Graphs"), 80)
page.i18n = "statistics"
page.setuser = "nobody"
page.setgroup = "nogroup"
-- plugin menu entry
entry(
{ "admin", "statistics", "graph", plugin },
- call("statistics_render"), _i18n( plugin ), i
+ call("statistics_render"), labels[plugin], i
).query = { timespan = span }
-- if more then one instance is found then generate submenu
end
function statistics_outputplugins()
- local plugins = { }
-
- for i, p in ipairs({ "rrdtool", "network", "unixsock", "csv" }) do
- plugins[p] = luci.i18n.translate( "stat_" .. p, p )
- end
+ local translate = luci.i18n.translate
+ local plugins = {
+ rrdtool = translate("RRDTool"),
+ network = translate("Network"),
+ unixsock = translate("UnixSock"),
+ csv = translate("CSV Output")
+ }
luci.template.render("admin_statistics/outputplugins", {plugins=plugins})
end
function statistics_systemplugins()
- local plugins = { }
-
- for i, p in ipairs({ "exec", "email", "df", "disk", "irq", "processes", "cpu" }) do
- plugins[p] = luci.i18n.translate( "stat_" .. p, p )
- end
+ local translate = luci.i18n.translate
+ local plugins = {
+ exec = translate("Exec"),
+ email = translate("Email"),
+ cpu = translate("Processor"),
+ df = translate("Disk Space Usage"),
+ disk = translate("Disk Usage"),
+ irq = translate("Interrupts"),
+ processes = translate("Processes"),
+ load = translate("System Load"),
+ }
luci.template.render("admin_statistics/systemplugins", {plugins=plugins})
end
function statistics_networkplugins()
- local plugins = { }
-
- for i, p in ipairs({ "interface", "netlink", "iptables", "tcpconns", "ping", "dns", "wireless" }) do
- plugins[p] = luci.i18n.translate( "stat_" .. p, p )
- end
+ local translate = luci.i18n.translate
+ local plugins = {
+ interface = translate("Interfaces"),
+ netlink = translate("Netlink"),
+ iptables = translate("Firewall"),
+ tcpconns = translate("TCP Connections"),
+ ping = translate("Ping"),
+ dns = translate("DNS"),
+ wireless = translate("Wireless")
+ }
luci.template.render("admin_statistics/networkplugins", {plugins=plugins})
end
local vars = luci.http.formvalue()
local req = luci.dispatcher.context.request
- local path = luci.dispatcher.context.dispatched.path
+ local path = luci.dispatcher.context.path
local uci = luci.model.uci.cursor()
local spans = luci.util.split( uci:get( "luci_statistics", "collectd_rrdtool", "RRATimespans" ), "%s+", nil, true )
local span = vars.timespan or uci:get( "luci_statistics", "rrdtool", "default_timespan" ) or spans[1]
local graph = luci.statistics.rrdtool.Graph( luci.util.parse_units( span ) )
+ -- deliver image
+ if vars.img then
+ local l12 = require "luci.ltn12"
+ local png = io.open(graph.opts.imgpath .. "/" .. vars.img:gsub("%.+", "."), "r")
+ if png then
+ luci.http.prepare_content("image/png")
+ l12.pump.all(l12.source.file(png), luci.http.write)
+ png:close()
+ end
+ return
+ end
+
local plugin, instances
local images = { }
-- find requested plugin and instance
- for i, p in ipairs( luci.dispatcher.context.dispatched.path ) do
- if luci.dispatcher.context.dispatched.path[i] == "graph" then
- plugin = luci.dispatcher.context.dispatched.path[i+1]
- instances = { luci.dispatcher.context.dispatched.path[i+2] }
- end
+ for i, p in ipairs( luci.dispatcher.context.path ) do
+ if luci.dispatcher.context.path[i] == "graph" then
+ plugin = luci.dispatcher.context.path[i+1]
+ instances = { luci.dispatcher.context.path[i+2] }
end
+ end
-- no instance requested, find all instances
if #instances == 0 then