* luci/statistics: implement timespan selection in public interface

This commit is contained in:
Jo-Philipp Wich 2008-06-03 19:05:34 +00:00
parent 56a23c609c
commit 71449d76e7
4 changed files with 39 additions and 18 deletions

View file

@ -1,12 +1,8 @@
module("luci.controller.luci_statistics.luci_statistics", package.seeall) module("luci.controller.luci_statistics.luci_statistics", package.seeall)
require("luci.fs")
require("luci.i18n")
require("luci.template")
function index() function index()
require("luci.fs")
require("luci.i18n") require("luci.i18n")
require("luci.statistics.datatree") require("luci.statistics.datatree")
@ -66,13 +62,19 @@ function index()
-- public views -- public views
entry({"freifunk", "statistics"}, call("statistics_index"), "Statistiken", 80).i18n = "statistics" entry({"freifunk", "statistics"}, call("statistics_index"), "Statistiken", 80).i18n = "statistics"
local vars = luci.http.formvalues()
local span = vars.timespan or nil
for i, plugin in ipairs( tree:plugins() ) do for i, plugin in ipairs( tree:plugins() ) do
-- get plugin instances -- get plugin instances
local instances = tree:plugin_instances( plugin ) local instances = tree:plugin_instances( plugin )
-- plugin menu entry -- plugin menu entry
_entry( { "freifunk", "statistics", plugin }, call("statistics_render"), _i18n( plugin ), i ) entry(
{ "freifunk", "statistics", plugin },
call("statistics_render"), _i18n( plugin ), i
).query = { timespan = span }
-- if more then one instance is found then generate submenu -- if more then one instance is found then generate submenu
if #instances > 1 then if #instances > 1 then
@ -81,13 +83,12 @@ function index()
entry( entry(
{ "freifunk", "statistics", plugin, inst }, { "freifunk", "statistics", plugin, inst },
call("statistics_render"), inst, j call("statistics_render"), inst, j
) ).query = { timespan = span }
end end
end end
end end
end end
function statistics_index() function statistics_index()
luci.template.render("admin_statistics/index") luci.template.render("admin_statistics/index")
end end
@ -127,9 +128,14 @@ function statistics_render( tree )
require("luci.statistics.rrdtool") require("luci.statistics.rrdtool")
require("luci.template") require("luci.template")
require("luci.model.uci")
local vars = luci.http.formvalues()
local req = luci.dispatcher.request local req = luci.dispatcher.request
local graph = luci.statistics.rrdtool.Graph() local uci = luci.model.uci.Session()
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 plugin = req[3] local plugin = req[3]
local instances = { req[4] } local instances = { req[4] }
@ -168,5 +174,10 @@ function statistics_render( tree )
end end
end end
luci.template.render("public_statistics/graph", { images=images, plugin=plugin } ) luci.template.render( "public_statistics/graph", {
images = images,
plugin = plugin,
timespans = spans,
current_timespan = span
} )
end end

View file

@ -22,6 +22,7 @@ stat_statistics = "Statistics"
stat_systemplugins = "System plugins" stat_systemplugins = "System plugins"
stat_networkplugins = "Network plugins" stat_networkplugins = "Network plugins"
stat_outputplugins = "Output plugins" stat_outputplugins = "Output plugins"
stat_showtimespan = "Display timespan »"
-- --

View file

@ -26,9 +26,9 @@ function Graph.__init__( self, timespan, opts )
self.i18n = luci.statistics.i18n.Instance( self ) self.i18n = luci.statistics.i18n.Instance( self )
-- options -- options
opts.timespan = timespan or sections.rrdtool.default_timespan or 900
opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle ~= "0" ) opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle ~= "0" )
opts.host = opts.host or sections.collectd.Hostname or luci.sys.hostname() opts.host = opts.host or sections.collectd.Hostname or luci.sys.hostname()
opts.timespan = opts.timespan or sections.rrdtool.default_timespan or 900
opts.width = opts.width or sections.rrdtool.image_width or 400 opts.width = opts.width or sections.rrdtool.image_width or 400
opts.rrdpath = opts.rrdpath or sections.collectd_rrdtool.DataDir or "/tmp/rrd" opts.rrdpath = opts.rrdpath or sections.collectd_rrdtool.DataDir or "/tmp/rrd"
opts.imgpath = opts.imgpath or sections.rrdtool.image_path or "/tmp/rrdimg" opts.imgpath = opts.imgpath or sections.rrdtool.image_path or "/tmp/rrdimg"
@ -63,7 +63,7 @@ function Graph.mkrrdpath( self, ... )
end end
function Graph.mkpngpath( self, ... ) function Graph.mkpngpath( self, ... )
return string.format( "%s/%s.png", self.opts.imgpath, self:_mkpath( ... ) ) return string.format( "%s/%s.%i.png", self.opts.imgpath, self:_mkpath( ... ), self.opts.timespan )
end end
function Graph.strippngpath( self, path ) function Graph.strippngpath( self, path )

View file

@ -2,6 +2,15 @@
<h1>Statistik</h1> <h1>Statistik</h1>
<form action="" method="get">
<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="<%:stat_showtimespan Display timespan &raquo;%>" />
</form>
<% for i, img in ipairs(images) do %> <% for i, img in ipairs(images) do %>
<img src="/rrdimg/<%=img%>" /> <img src="/rrdimg/<%=img%>" />
<% end %> <% end %>