X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-statistics%2Fluasrc%2Fcontroller%2Fluci_statistics%2Fluci_statistics.lua;h=5729bb186a1591fec614f6eb16f0cebb13b29b53;hp=ccea56e2b85a488e6795e1a49c219fc521c5c969;hb=ccdc6535a9e1eefa109bc491a204e32281d13063;hpb=c833c967505440717343dc5bd580dbb286e54b3f 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 ccea56e2b..5729bb186 100644 --- a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua +++ b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua @@ -2,6 +2,7 @@ Luci statistics - statistics controller module (c) 2008 Freifunk Leipzig / Jo-Philipp Wich +(c) 2012 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. @@ -9,8 +10,6 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -$Id$ - ]]-- module("luci.controller.luci_statistics.luci_statistics", package.seeall) @@ -21,9 +20,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] @@ -53,28 +49,30 @@ function index() 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") + unixsock = _("UnixSock"), + 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", "iwinfo" } + 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"}, 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 @@ -85,7 +83,6 @@ function index() ) e.index = true - e.i18n = "rrdtool" for j, plugin in luci.util.vspairs( plugins ) do _entry( @@ -100,14 +97,18 @@ function index() -- output views local page = entry( { "admin", "statistics", "graph" }, template("admin_statistics/index"), _("Graphs"), 80) - page.i18n = "statistics" 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 + local _, plugin, idx + for _, plugin, idx in luci.util.vspairs( tree:plugins() ) do -- get plugin instances local instances = tree:plugin_instances( plugin ) @@ -115,17 +116,18 @@ function index() -- 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 @@ -143,9 +145,13 @@ 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 + local i, p, inst, idx -- deliver image if vars.img then @@ -184,8 +190,8 @@ function statistics_render() -- 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 @@ -196,6 +202,8 @@ function statistics_render() plugin = plugin, timespans = spans, current_timespan = span, + hosts = hosts, + current_host = host, is_index = is_index } ) end