applications/luci-statistics: make host selectable if collectd-mod-network server...
authorPatrick Grimm <patrick@lunatiki.de>
Sun, 19 Feb 2012 15:11:23 +0000 (15:11 +0000)
committerPatrick Grimm <patrick@lunatiki.de>
Sun, 19 Feb 2012 15:11:23 +0000 (15:11 +0000)
13 files changed:
applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
applications/luci-statistics/luasrc/statistics/datatree.lua
applications/luci-statistics/luasrc/statistics/rrdtool.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/dns.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/memory.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua
applications/luci-statistics/luasrc/view/public_statistics/graph.htm
applications/luci-statistics/root/etc/config/luci_statistics
contrib/package/luci/Makefile

index ccea56e..2e25154 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]
@@ -106,6 +103,10 @@ function index()
 
        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
 
@@ -116,7 +117,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
@@ -125,7 +126,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 +144,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 +200,8 @@ function statistics_render()
                plugin           = plugin,
                timespans        = spans,
                current_timespan = span,
+               hosts            = hosts,
+               current_host     = host,
                is_index         = is_index
        } )
 end
index b494dc1..d6de6fa 100644 (file)
@@ -192,3 +192,16 @@ function Instance.data_instances( self, plugin, instance, dtype )
 
        return rv
 end
+
+function Instance.host_instances( self )
+       local hosts_path = fs.glob(self._rrddir..'/*')
+       local hosts = { }
+       k = 1
+       for v in hosts_path do
+               hosts[k] = fs.basename(v)
+               k=k+1
+       end
+
+       return hosts
+end
+
index b540dd1..844c157 100644 (file)
@@ -34,11 +34,6 @@ function Graph.__init__( self, timespan, opts )
        local uci = luci.model.uci.cursor()
        local sections = uci:get_all( "luci_statistics" )
 
-       -- helper classes
-       self.colors = luci.statistics.rrdtool.colors.Instance()
-       self.tree   = luci.statistics.datatree.Instance()
-       self.i18n   = luci.statistics.i18n.Instance( self )
-
        -- options
        opts.timespan  = timespan       or sections.rrdtool.default_timespan or 900
        opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle == "1" )
@@ -49,6 +44,11 @@ function Graph.__init__( self, timespan, opts )
        opts.rrdpath   = opts.rrdpath:gsub("/$","")
        opts.imgpath   = opts.imgpath:gsub("/$","")
 
+       -- helper classes
+       self.colors = luci.statistics.rrdtool.colors.Instance()
+       self.tree   = luci.statistics.datatree.Instance(opts.host)
+       self.i18n   = luci.statistics.i18n.Instance( self )
+
        -- rrdtool default args
        self.args = {
                "-a", "PNG",
index 12a1101..449a4e2 100644 (file)
@@ -15,7 +15,7 @@ $Id$
 
 module("luci.statistics.rrdtool.definitions.conntrack",package.seeall)
 
-function rrdargs( graph, host, plugin, plugin_instance, dtype )
+function rrdargs( graph, plugin, plugin_instance, dtype )
        return {
                title = "%H: Conntrack entries",
                vlabel = "Count",
index 41bae39..adc3f28 100644 (file)
@@ -15,7 +15,7 @@ $Id: cpu.lua 2274 2008-06-03 23:15:16Z jow $
 
 module("luci.statistics.rrdtool.definitions.cpu",package.seeall)
 
-function rrdargs( graph, host, plugin, plugin_instance, dtype )
+function rrdargs( graph, plugin, plugin_instance, dtype )
 
        return {
                title = "%H: Processor usage on core #%pi",
index 4f328c3..94a148d 100644 (file)
@@ -13,7 +13,7 @@ You may obtain a copy of the License at
 
 module("luci.statistics.rrdtool.definitions.dns", package.seeall)
 
-function rrdargs( graph, host, plugin, plugin_instance )
+function rrdargs( graph, plugin, plugin_instance )
 
        local traffic = {
                title = "%H: DNS traffic", vlabel = "Bit/s",
index 35bc25b..9b698d2 100644 (file)
@@ -15,7 +15,7 @@ $Id$
 
 module("luci.statistics.rrdtool.definitions.interface", package.seeall)
 
-function rrdargs( graph, host, plugin, plugin_instance )
+function rrdargs( graph, plugin, plugin_instance )
 
        --
        -- traffic diagram
index 54c869f..0c6eed9 100644 (file)
@@ -15,7 +15,7 @@ $Id$
 
 module("luci.statistics.rrdtool.definitions.iwinfo", package.seeall)
 
-function rrdargs( graph, host, plugin, plugin_instance )
+function rrdargs( graph, plugin, plugin_instance )
 
        --
        -- signal/noise diagram
index 093f992..a1c65f5 100644 (file)
@@ -11,7 +11,7 @@ You may obtain a copy of the License at
 
 module("luci.statistics.rrdtool.definitions.memory",package.seeall)
 
-function rrdargs( graph, host, plugin, plugin_instance, dtype )
+function rrdargs( graph, plugin, plugin_instance, dtype )
 
        return {
                title = "%H: Memory usage",
index 3ee3910..3ca2f03 100644 (file)
@@ -13,8 +13,6 @@ You may obtain a copy of the License at
 
 module("luci.statistics.rrdtool.definitions.olsrd", package.seeall)
 
-local tree = luci.statistics.datatree.Instance()
-
 function rrdargs( graph, plugin, plugin_instance, dtype )
        local g = { }
 
@@ -77,7 +75,7 @@ function rrdargs( graph, plugin, plugin_instance, dtype )
                        }
                }
 
-               local instances = tree:data_instances(plugin, plugin_instance, "signal_quality")
+               local instances = graph.tree:data_instances(plugin, plugin_instance, "signal_quality")
                table.sort(instances)
 
                -- define one diagram per host, containing the rx and lq values
index dfe47b3..e9b0baf 100644 (file)
@@ -17,12 +17,18 @@ $Id$
 <h2><a id="content" name="content"><%:Statistics%></a></h2>
 
 <form action="" method="get">
+       <select name="host">
+               <% for i, host in ipairs(hosts) do %>
+                       <option<% if host == current_host then %> selected="selected"<% end %>><%=pcdata(host)%></option>
+               <% end %>
+       </select>
+       <input class="cbi-button cbi-button-apply" type="submit" name="submit" value="<%:Display Host »%>" />
        <select name="timespan">
                <% for i, span in ipairs(timespans) do %>
                        <option<% if span == current_timespan then %> selected="selected"<% end %>><%=span%></option>
                <% end %>
        </select>
-       <input type="submit" name="submit" value="<%:Display timespan »%>" />
+       <input class="cbi-button cbi-button-apply" type="submit" name="submit" value="<%:Display timespan »%>" />
 </form>
 
 <br />
@@ -39,3 +45,4 @@ $Id$
 </div>
 
 <%+footer%>
+
index 4d26b93..a1e6a6b 100644 (file)
@@ -113,7 +113,7 @@ config 'statistics' 'collectd_cpu'
 
 config 'statistics' 'collectd_rrdtool'
        option 'enable' '1'
-       option 'DataDir' '/tmp'
+       option 'DataDir' '/tmp/rrd'
        option 'RRARows' '100'
        option 'RRASingle' '1'
        option 'RRATimespans' '1hour 1day 1week 1month 1year'
index 94a3c91..3b60958 100644 (file)
@@ -357,7 +357,8 @@ $(eval $(call application,statistics,LuCI Statistics Application,\
        +PACKAGE_luci-app-statistics:collectd-mod-rrdtool \
        +PACKAGE_luci-app-statistics:collectd-mod-iwinfo \
        +PACKAGE_luci-app-statistics:collectd-mod-interface \
-       +PACKAGE_luci-app-statistics:collectd-mod-load))
+       +PACKAGE_luci-app-statistics:collectd-mod-load)) \
+       +PACKAGE_luci-app-statistics:collectd-mod-network))
 
 
 $(eval $(call application,diag-core,LuCI Diagnostics Tools (Core)))