Add NUT UPS support to luci-statistics
[project/luci.git] / applications / luci-statistics / luasrc / controller / luci_statistics / luci_statistics.lua
index a49c404..7d8e6bf 100644 (file)
@@ -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 <plugin>.so where <plugin> is derived from the called path
        function _entry( path, ... )
                local file = path[5] or path[4]
@@ -53,6 +50,7 @@ function index()
                memory          = _("Memory"),
                netlink         = _("Netlink"),
                network         = _("Network"),
+               nut             = _("UPS"),
                olsrd           = _("OLSRd"),
                ping            = _("Ping"),
                processes       = _("Processes"),
@@ -69,8 +67,7 @@ function index()
        }
 
        -- 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
@@ -85,7 +82,6 @@ function index()
                )
 
                e.index = true
-               e.i18n  = "rrdtool"
 
                for j, plugin in luci.util.vspairs( plugins ) do
                        _entry(
@@ -99,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
 
@@ -115,8 +114,8 @@ function index()
                -- plugin menu entry
                entry(
                        { "admin", "statistics", "graph", plugin },
-                       template("admin_statistics/index"), labels[plugin], i
-               ).query = { timespan = span }
+                       call("statistics_render"), labels[plugin], i
+               ).query = { timespan = span , host = host }
 
                -- if more then one instance is found then generate submenu
                if #instances > 1 then
@@ -125,7 +124,7 @@ function index()
                                entry(
                                        { "admin", "statistics", "graph", plugin, inst },
                                        call("statistics_render"), inst, j
-                               ).query = { timespan = span }
+                               ).query = { timespan = span , host = host }
                        end
                end
        end
@@ -143,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
 
@@ -196,6 +198,8 @@ function statistics_render()
                plugin           = plugin,
                timespans        = spans,
                current_timespan = span,
+               hosts            = hosts,
+               current_host     = host,
                is_index         = is_index
        } )
 end