X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=applications%2Fluci-statistics%2Fluasrc%2Fcontroller%2Fluci_statistics%2Fluci_statistics.lua;h=869384c0a693a1fc87a6c8223c791d82d65e457a;hb=839dcdc01299869bc714990c19d8e244f18318b5;hp=2508f9308cc0b9960b863eb742e96c3c614f2dfb;hpb=6acb5c2ab4093973d03657f9eea248c135f58cfc;p=project%2Fluci.git diff --git a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua index 2508f9308..869384c0a 100644 --- a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua +++ b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua @@ -21,9 +21,6 @@ function index() require("luci.util") require("luci.statistics.datatree") - -- get rrd data tree - local tree = luci.statistics.datatree.Instance() - -- override entry(): check for existance .so where is derived from the called path function _entry( path, ... ) local file = path[5] or path[4] @@ -37,40 +34,40 @@ function index() s_system = _("System plugins"), s_network = _("Network plugins"), - rrdtool = _("RRDTool"), - network = _("Network"), - unixsock = _("UnixSock"), - conntrack = _("Conntrack"), - csv = _("CSV Output"), - exec = _("Exec"), - email = _("Email"), + conntrack = _("Conntrack"), cpu = _("Processor"), + csv = _("CSV Output"), df = _("Disk Space Usage"), disk = _("Disk Usage"), + dns = _("DNS"), + email = _("Email"), + exec = _("Exec"), + interface = _("Interfaces"), + iptables = _("Firewall"), irq = _("Interrupts"), - processes = _("Processes"), + iwinfo = _("Wireless"), load = _("System Load"), - interface = _("Interfaces"), memory = _("Memory"), netlink = _("Netlink"), - iptables = _("Firewall"), - tcpconns = _("TCP Connections"), + network = _("Network"), + nut = _("UPS"), + olsrd = _("OLSRd"), ping = _("Ping"), - dns = _("DNS"), - wireless = _("Wireless"), - olsrd = _("OLSRd") + processes = _("Processes"), + rrdtool = _("RRDTool"), + tcpconns = _("TCP Connections"), + unixsock = _("UnixSock") } -- our collectd menu local collectd_menu = { - output = { "rrdtool", "network", "unixsock", "csv" }, - system = { "exec", "email", "cpu", "df", "disk", "irq", "memory", "processes", "load" }, - network = { "interface", "netlink", "iptables", "conntrack", "tcpconns", "ping", "dns", "wireless", "olsrd" } + output = { "csv", "network", "rrdtool", "unixsock" }, + system = { "cpu", "df", "disk", "email", "exec", "irq", "load", "memory", "nut", "processes" }, + network = { "conntrack", "dns", "interface", "iptables", "netlink", "olsrd", "ping", "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 @@ -81,12 +78,10 @@ function index() 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( @@ -100,13 +95,16 @@ function index() 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 + + -- get rrd data tree + local tree = luci.statistics.datatree.Instance(host) for i, plugin in luci.util.vspairs( tree:plugins() ) do @@ -117,7 +115,7 @@ function index() entry( { "admin", "statistics", "graph", plugin }, call("statistics_render"), labels[plugin], i - ).query = { timespan = span } + ).query = { timespan = span , host = host } -- if more then one instance is found then generate submenu if #instances > 1 then @@ -126,61 +124,12 @@ function index() entry( { "admin", "statistics", "graph", plugin, inst }, call("statistics_render"), inst, j - ).query = { timespan = span } + ).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") @@ -193,7 +142,10 @@ function statistics_render() 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 @@ -246,6 +198,8 @@ function statistics_render() plugin = plugin, timespans = spans, current_timespan = span, + hosts = hosts, + current_host = host, is_index = is_index } ) end