summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-statistics
diff options
context:
space:
mode:
authorPatrick Grimm <patrick@lunatiki.de>2012-02-19 15:11:23 +0000
committerPatrick Grimm <patrick@lunatiki.de>2012-02-19 15:11:23 +0000
commitad7aecad88399b917b6a96952f3645c475e73c59 (patch)
treed582023a76a305ef0150eaa670c92d9ca6fb012b /applications/luci-statistics
parent2ff0ec12ac2acc140680f457f0699b88676d8cfb (diff)
applications/luci-statistics: make host selectable if collectd-mod-network server is on
Diffstat (limited to 'applications/luci-statistics')
-rw-r--r--applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua18
-rw-r--r--applications/luci-statistics/luasrc/statistics/datatree.lua13
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool.lua10
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua2
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua2
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool/definitions/dns.lua2
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua2
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua2
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool/definitions/memory.lua2
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua4
-rw-r--r--applications/luci-statistics/luasrc/view/public_statistics/graph.htm9
-rw-r--r--applications/luci-statistics/root/etc/config/luci_statistics2
12 files changed, 46 insertions, 22 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 ccea56e2b..2e2515412 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 <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
diff --git a/applications/luci-statistics/luasrc/statistics/datatree.lua b/applications/luci-statistics/luasrc/statistics/datatree.lua
index b494dc108..d6de6fa21 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 b540dd15f..844c157d1 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 12a1101b7..449a4e214 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 41bae391f..adc3f284b 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 4f328c3c0..94a148d81 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 35bc25b56..9b698d263 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 54c869f7f..0c6eed993 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 093f9923b..a1c65f56d 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 3ee39102e..3ca2f03ec 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 dfe47b34e..e9b0baf05 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$
<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%>
+
diff --git a/applications/luci-statistics/root/etc/config/luci_statistics b/applications/luci-statistics/root/etc/config/luci_statistics
index 4d26b933d..a1e6a6b86 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'