Luci statistics - statistics controller module
(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+(c) 2012 Jo-Philipp Wich <xm@subsignal.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
http://www.apache.org/licenses/LICENSE-2.0
-$Id$
-
]]--
module("luci.controller.luci_statistics.luci_statistics", package.seeall)
require("luci.util")
require("luci.statistics.datatree")
- -- 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]
interface = _("Interfaces"),
iptables = _("Firewall"),
irq = _("Interrupts"),
+ iwinfo = _("Wireless"),
load = _("System Load"),
memory = _("Memory"),
netlink = _("Netlink"),
network = _("Network"),
+ nut = _("UPS"),
olsrd = _("OLSRd"),
ping = _("Ping"),
processes = _("Processes"),
rrdtool = _("RRDTool"),
+ splash_leases = _("Splash Leases"),
tcpconns = _("TCP Connections"),
unixsock = _("UnixSock"),
- wireless = _("Wireless")
+ uptime = _("Uptime")
}
-- our collectd menu
local collectd_menu = {
output = { "csv", "network", "rrdtool", "unixsock" },
- system = { "cpu", "df", "disk", "email", "exec", "irq", "load", "memory", "processes" },
- network = { "conntrack", "dns", "interface", "iptables", "netlink", "olsrd", "ping", "tcpconns", "wireless" }
+ system = { "cpu", "df", "disk", "email", "exec", "irq", "load", "memory", "nut", "processes", "uptime" },
+ network = { "conntrack", "dns", "interface", "iptables", "netlink", "olsrd", "ping", "splash_leases", "tcpconns", "iwinfo" }
}
-- create toplevel menu nodes
- local st = entry({"admin", "statistics"}, call("statistics_index"), _("Statistics"), 80)
- st.i18n = "statistics"
+ local st = entry({"admin", "statistics"}, template("admin_statistics/index"), _("Statistics"), 80)
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
local e = entry(
{ "admin", "statistics", "collectd", section },
- call( "statistics_" .. section .. "plugins" ),
- labels["s_"..section], index * 10
+ firstchild(), labels["s_"..section], index * 10
)
e.index = true
- e.i18n = "rrdtool"
for j, plugin in luci.util.vspairs( plugins ) do
_entry(
end
-- output views
- local page = entry( { "admin", "statistics", "graph" }, call("statistics_index"), _("Graphs"), 80)
- page.i18n = "statistics"
+ local page = entry( { "admin", "statistics", "graph" }, template("admin_statistics/index"), _("Graphs"), 80)
page.setuser = "nobody"
page.setgroup = "nogroup"
local vars = luci.http.formvalue(nil, true)
local span = vars.timespan or nil
+ local host = vars.host or nil
- for i, plugin in luci.util.vspairs( tree:plugins() ) do
+ -- get rrd data tree
+ local tree = luci.statistics.datatree.Instance(host)
+
+ local _, plugin, idx
+ for _, plugin, idx in luci.util.vspairs( tree:plugins() ) do
-- get plugin instances
local instances = tree:plugin_instances( plugin )
-- plugin menu entry
entry(
{ "admin", "statistics", "graph", plugin },
- call("statistics_render"), labels[plugin], i
- ).query = { timespan = span }
+ call("statistics_render"), labels[plugin], idx
+ ).query = { timespan = span , host = host }
-- if more then one instance is found then generate submenu
if #instances > 1 then
- for j, inst in luci.util.vspairs(instances) do
+ local _, inst, idx2
+ for _, inst, idx2 in luci.util.vspairs(instances) do
-- instance menu entry
entry(
{ "admin", "statistics", "graph", plugin, inst },
- call("statistics_render"), inst, j
- ).query = { timespan = span }
+ call("statistics_render"), inst, idx2
+ ).query = { timespan = span , host = host }
end
end
end
end
-function statistics_index()
- luci.template.render("admin_statistics/index")
-end
-
-function statistics_outputplugins()
- 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 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 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"),
- olsrd = translate("OLSRd")
- }
-
- luci.template.render("admin_statistics/networkplugins", {plugins=plugins})
-end
-
-
function statistics_render()
require("luci.statistics.rrdtool")
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 ) )
+ local host = vars.host or uci:get( "luci_statistics", "collectd", "Hostname" ) or luci.sys.hostname()
+ local opts = { host = vars.host }
+ local graph = luci.statistics.rrdtool.Graph( luci.util.parse_units( span ), opts )
+ local hosts = graph.tree:host_instances()
local is_index = false
+ local i, p, inst, idx
-- deliver image
if vars.img then
-- render graphs
- for i, inst in ipairs( instances ) do
- for i, img in ipairs( graph:render( plugin, inst, is_index ) ) do
+ for i, inst in luci.util.vspairs( instances ) do
+ for i, img in luci.util.vspairs( graph:render( plugin, inst, is_index ) ) do
table.insert( images, graph:strippngpath( img ) )
images[images[#images]] = inst
end
plugin = plugin,
timespans = spans,
current_timespan = span,
+ hosts = hosts,
+ current_host = host,
is_index = is_index
} )
end