summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2008-06-03 19:05:34 +0000
committerJo-Philipp Wich <jow@openwrt.org>2008-06-03 19:05:34 +0000
commit71449d76e71db089dfb158710057aecba7de8a59 (patch)
tree3ca864247b746e0dfc16ac7f873a00b2fb8a559e
parent56a23c609c30cf6c477bf6523661a44821da1819 (diff)
* luci/statistics: implement timespan selection in public interface
-rw-r--r--applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua37
-rw-r--r--applications/luci-statistics/luasrc/i18n/statistics.en1
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool.lua10
-rw-r--r--applications/luci-statistics/luasrc/view/public_statistics/graph.htm9
4 files changed, 39 insertions, 18 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 7fdedfbec..c621ee063 100644
--- a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
+++ b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
@@ -1,12 +1,8 @@
module("luci.controller.luci_statistics.luci_statistics", package.seeall)
-require("luci.fs")
-require("luci.i18n")
-require("luci.template")
-
-
function index()
+ require("luci.fs")
require("luci.i18n")
require("luci.statistics.datatree")
@@ -62,17 +58,23 @@ function index()
_entry({"admin", "statistics", "network", "dns"}, cbi("luci_statistics/dns"), _i18n("dns"), 60)
_entry({"admin", "statistics", "network", "wireless"}, cbi("luci_statistics/wireless"), _i18n("wireless"), 70)
-
+
-- public views
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
-- get plugin instances
local instances = tree:plugin_instances( plugin )
-- 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 #instances > 1 then
@@ -81,13 +83,12 @@ function index()
entry(
{ "freifunk", "statistics", plugin, inst },
call("statistics_render"), inst, j
- )
+ ).query = { timespan = span }
end
- end
+ end
end
end
-
function statistics_index()
luci.template.render("admin_statistics/index")
end
@@ -127,9 +128,14 @@ function statistics_render( tree )
require("luci.statistics.rrdtool")
require("luci.template")
+ require("luci.model.uci")
- local req = luci.dispatcher.request
- local graph = luci.statistics.rrdtool.Graph()
+ local vars = luci.http.formvalues()
+ local req = luci.dispatcher.request
+ 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 instances = { req[4] }
@@ -168,5 +174,10 @@ function statistics_render( tree )
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
diff --git a/applications/luci-statistics/luasrc/i18n/statistics.en b/applications/luci-statistics/luasrc/i18n/statistics.en
index 84f1c0e23..046fea20c 100644
--- a/applications/luci-statistics/luasrc/i18n/statistics.en
+++ b/applications/luci-statistics/luasrc/i18n/statistics.en
@@ -22,6 +22,7 @@ stat_statistics = "Statistics"
stat_systemplugins = "System plugins"
stat_networkplugins = "Network plugins"
stat_outputplugins = "Output plugins"
+stat_showtimespan = "Display timespan &raquo;"
--
diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-statistics/luasrc/statistics/rrdtool.lua
index 85741a4b7..c2ac7a8e6 100644
--- a/applications/luci-statistics/luasrc/statistics/rrdtool.lua
+++ b/applications/luci-statistics/luasrc/statistics/rrdtool.lua
@@ -26,9 +26,9 @@ function Graph.__init__( self, timespan, opts )
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 ~= "0" )
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.rrdpath = opts.rrdpath or sections.collectd_rrdtool.DataDir or "/tmp/rrd"
opts.imgpath = opts.imgpath or sections.rrdtool.image_path or "/tmp/rrdimg"
@@ -63,7 +63,7 @@ function Graph.mkrrdpath( self, ... )
end
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
function Graph.strippngpath( self, path )
@@ -100,7 +100,7 @@ function Graph._rrdtool( self, def, rrd )
-- construct commandline from def stack
for i, opt in ipairs(def) do
opt = opt .. "" -- force string
-
+
if rrd then
opt = opt:gsub( "{file}", rrd )
end
@@ -177,7 +177,7 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index )
-- is subsequent source without overlay: source_stk = source_nnl + previous_stk
else
- -- create cdef statement
+ -- create cdef statement
_tif( _args, "CDEF:%s_stk=%s_nnl,%s_stk,+", source.sname, source.sname, prev )
end
@@ -574,7 +574,7 @@ function Graph.render( self, plugin, plugin_instance )
local png = self:mkpngpath( plugin, plugin_instance, dtype, inst )
local rrd = self:mkrrdpath( plugin, plugin_instance, dtype, inst )
local args = { png, "-t", title }
-
+
for i, o in ipairs(self.defs.definitions[dtype]) do
table.insert( args, o )
end
diff --git a/applications/luci-statistics/luasrc/view/public_statistics/graph.htm b/applications/luci-statistics/luasrc/view/public_statistics/graph.htm
index 33678bdcb..f3be3ab8a 100644
--- a/applications/luci-statistics/luasrc/view/public_statistics/graph.htm
+++ b/applications/luci-statistics/luasrc/view/public_statistics/graph.htm
@@ -2,6 +2,15 @@
<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 %>
<img src="/rrdimg/<%=img%>" />
<% end %>