From ad7aecad88399b917b6a96952f3645c475e73c59 Mon Sep 17 00:00:00 2001 From: Patrick Grimm Date: Sun, 19 Feb 2012 15:11:23 +0000 Subject: [PATCH] applications/luci-statistics: make host selectable if collectd-mod-network server is on --- .../luci_statistics/luci_statistics.lua | 18 ++++++++++++------ .../luasrc/statistics/datatree.lua | 13 +++++++++++++ .../luasrc/statistics/rrdtool.lua | 10 +++++----- .../rrdtool/definitions/conntrack.lua | 2 +- .../statistics/rrdtool/definitions/cpu.lua | 2 +- .../statistics/rrdtool/definitions/dns.lua | 2 +- .../rrdtool/definitions/interface.lua | 2 +- .../statistics/rrdtool/definitions/iwinfo.lua | 2 +- .../statistics/rrdtool/definitions/memory.lua | 2 +- .../statistics/rrdtool/definitions/olsrd.lua | 4 +--- .../luasrc/view/public_statistics/graph.htm | 9 ++++++++- .../root/etc/config/luci_statistics | 2 +- contrib/package/luci/Makefile | 3 ++- 13 files changed, 48 insertions(+), 23 deletions(-) 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 ccea56e2b8..2e25154123 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] @@ -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 diff --git a/applications/luci-statistics/luasrc/statistics/datatree.lua b/applications/luci-statistics/luasrc/statistics/datatree.lua index b494dc1084..d6de6fa217 100644 --- a/applications/luci-statistics/luasrc/statistics/datatree.lua +++ b/applications/luci-statistics/luasrc/statistics/datatree.lua @@ -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 + diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-statistics/luasrc/statistics/rrdtool.lua index b540dd15f0..844c157d15 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool.lua @@ -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", diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua index 12a1101b74..449a4e2147 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua @@ -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", diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua index 41bae391fe..adc3f284b2 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua @@ -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", diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/dns.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/dns.lua index 4f328c3c02..94a148d810 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/dns.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/dns.lua @@ -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", diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua index 35bc25b56e..9b698d263a 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua @@ -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 diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua index 54c869f7f0..0c6eed9936 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua @@ -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 diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/memory.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/memory.lua index 093f9923b2..a1c65f56d7 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/memory.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/memory.lua @@ -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", diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua index 3ee39102e6..3ca2f03ec8 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua @@ -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 diff --git a/applications/luci-statistics/luasrc/view/public_statistics/graph.htm b/applications/luci-statistics/luasrc/view/public_statistics/graph.htm index dfe47b34e0..e9b0baf05e 100644 --- a/applications/luci-statistics/luasrc/view/public_statistics/graph.htm +++ b/applications/luci-statistics/luasrc/view/public_statistics/graph.htm @@ -17,12 +17,18 @@ $Id$

<%:Statistics%>

+ + - +

@@ -39,3 +45,4 @@ $Id$ <%+footer%> + diff --git a/applications/luci-statistics/root/etc/config/luci_statistics b/applications/luci-statistics/root/etc/config/luci_statistics index 4d26b933d9..a1e6a6b86b 100644 --- a/applications/luci-statistics/root/etc/config/luci_statistics +++ b/applications/luci-statistics/root/etc/config/luci_statistics @@ -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' diff --git a/contrib/package/luci/Makefile b/contrib/package/luci/Makefile index 94a3c918ff..3b609582e4 100644 --- a/contrib/package/luci/Makefile +++ b/contrib/package/luci/Makefile @@ -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))) -- 2.30.2