applications/luci-statistics: make host selectable if collectd-mod-network server is on
This commit is contained in:
parent
2ff0ec12ac
commit
ad7aecad88
13 changed files with 48 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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%>
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Reference in a new issue