summaryrefslogtreecommitdiffhomepage
path: root/applications
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2008-06-01 03:12:48 +0000
committerJo-Philipp Wich <jow@openwrt.org>2008-06-01 03:12:48 +0000
commit1da5feb9f720fd48a886aad09df91bd8cc9df4c8 (patch)
tree37f7409317502086de0b5fc3fdca7fbbb03d165a /applications
parent9688e102c4c1bc9c9c816797826d86189c94a430 (diff)
* luci/statistics: let rrdtool.lua use values from the configuration, added irq diagram model
Diffstat (limited to 'applications')
-rw-r--r--applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua3
-rw-r--r--applications/luci-statistics/luasrc/i18n/statistics.en4
-rw-r--r--applications/luci-statistics/luasrc/statistics/datatree.lua74
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool.lua26
-rw-r--r--applications/luci-statistics/luasrc/statistics/rrdtool/definitions/irq/irq.lua10
-rw-r--r--applications/luci-statistics/luasrc/view/public_statistics/graph.htm2
6 files changed, 81 insertions, 38 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 566e13757..f19d2cdb7 100644
--- a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
+++ b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
@@ -60,6 +60,7 @@ function index()
_entry({"admin", "statistics", "network", "tcpconns"}, cbi("luci_statistics/tcpconns"), "Verbindungen", 40)
_entry({"admin", "statistics", "network", "ping"}, cbi("luci_statistics/ping"), "Ping", 50)
_entry({"admin", "statistics", "network", "dns"}, cbi("luci_statistics/dns"), "DNS", 60)
+ _entry({"admin", "statistics", "network", "wireless"}, cbi("luci_statistics/wireless"), "Drahtlos", 70)
-- public views
@@ -169,7 +170,7 @@ function statistics_render( tree )
-- render graphs
for i, inst in ipairs( instances ) do
for i, img in ipairs( graph:render( plugin, inst ) ) do
- table.insert( images, img )
+ table.insert( images, graph:strippngpath( img ) )
end
end
diff --git a/applications/luci-statistics/luasrc/i18n/statistics.en b/applications/luci-statistics/luasrc/i18n/statistics.en
index 25a9be674..632fd568e 100644
--- a/applications/luci-statistics/luasrc/i18n/statistics.en
+++ b/applications/luci-statistics/luasrc/i18n/statistics.en
@@ -8,6 +8,7 @@ stat_wireless = "Wireless"
stat_tcpconns = "TCP Connections"
stat_interface = "Interfaces"
stat_df = "Disk Space Usage"
+stat_irq = "Interrupts"
-- diagrams
stat_dg_title_wireless__signal_noise = "%H: Wireless - Signal Noise Ratio"
@@ -90,3 +91,6 @@ stat_dg_label_df = "Bytes"
stat_ds_df__free = "%ds"
stat_ds_df__used = "%ds"
+stat_dg_title_irq = "%H: Interrupts"
+stat_dg_label_irq = "Issues/s"
+stat_ds_irq = "IRQ %di"
diff --git a/applications/luci-statistics/luasrc/statistics/datatree.lua b/applications/luci-statistics/luasrc/statistics/datatree.lua
index 82e7a281d..e3c9e34bb 100644
--- a/applications/luci-statistics/luasrc/statistics/datatree.lua
+++ b/applications/luci-statistics/luasrc/statistics/datatree.lua
@@ -12,7 +12,7 @@ Instance = util.class()
function Instance.__init__( self, host )
self._host = host or sections.collectd.Hostname or sys.hostname()
self._libdir = sections.collectd.PluginDir or "/usr/lib/collectd"
- self._rrddir = sections.collectd_rrdtool.DataDir or "/tmp"
+ self._rrddir = sections.collectd_rrdtool.DataDir or "/tmp/rrd"
self._libdir = self._libdir:gsub("/$","")
self._rrddir = self._rrddir:gsub("/$","")
@@ -51,38 +51,48 @@ function Instance._scan( self )
end
for plugin, instances in pairs( self._plugins ) do
- for i, dir in ipairs( fs.dir( self:_mkpath() ) ) do
- if dir:find( plugin .. "%-" ) or dir == plugin then
- local instance = ""
- if dir ~= plugin then
- instance = dir:gsub( plugin .. "%-", "", 1 )
- end
+ local dirs = fs.dir( self:_mkpath() )
+
+ if type(dirs) == "table" then
+ for i, dir in ipairs(dirs) do
+ if dir:find( plugin .. "%-" ) or dir == plugin then
+ local instance = ""
+
+ if dir ~= plugin then
+ instance = dir:gsub( plugin .. "%-", "", 1 )
+ end
- instances[instance] = { }
+ instances[instance] = { }
+ end
end
end
for instance, data_instances in pairs( instances ) do
- for i, file in ipairs( fs.dir( self:_mkpath( plugin, instance ) ) ) do
- if file:find("%.rrd") then
- file = file:gsub("%.rrd","")
-
- local data_type
- local data_instance
-
- if file:find("%-") then
- data_type = file:gsub( "%-.+","" )
- data_instance = file:gsub( "[^%-]-%-", "", 1 )
- else
- data_type = file
- data_instance = ""
- end
- if not data_instances[data_type] then
- data_instances[data_type] = { data_instance }
- else
- table.insert( data_instances[data_type], data_instance )
+ dirs = fs.dir( self:_mkpath( plugin, instance ) )
+
+ if type(dirs) == "table" then
+ for i, file in ipairs(dirs) do
+ if file:find("%.rrd") then
+ file = file:gsub("%.rrd","")
+
+ local data_type
+ local data_instance
+
+ if file:find("%-") then
+ data_type = file:gsub( "%-.+","" )
+ data_instance = file:gsub( "[^%-]-%-", "", 1 )
+ else
+ data_type = file
+ data_instance = ""
+ end
+
+ if not data_instances[data_type] then
+ data_instances[data_type] = { data_instance }
+ else
+ table.insert( data_instances[data_type], data_instance )
+ end
end
end
end
@@ -115,9 +125,12 @@ end
function Instance.data_types( self, plugin, instance )
local rv = { }
+ local p = self._plugins[plugin]
- for type, val in pairs( self._plugins[plugin][instance] ) do
- table.insert( rv, type )
+ if type(p) == "table" and type(p[instance]) == "table" then
+ for type, val in pairs(p[instance]) do
+ table.insert( rv, type )
+ end
end
return rv
@@ -125,9 +138,10 @@ end
function Instance.data_instances( self, plugin, instance, dtype )
local rv = { }
+ local p = self._plugins[plugin]
- if type(self._plugins[plugin][instance][dtype]) == "table" then
- for i, instance in ipairs( self._plugins[plugin][instance][dtype] ) do
+ if type(p) == "table" and type(p[instance]) == "table" and type(p[instance][dtype]) == "table" then
+ for i, instance in ipairs(p[instance][dtype]) do
table.insert( rv, instance )
end
end
diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-statistics/luasrc/statistics/rrdtool.lua
index cdcf9ff3e..85741a4b7 100644
--- a/applications/luci-statistics/luasrc/statistics/rrdtool.lua
+++ b/applications/luci-statistics/luasrc/statistics/rrdtool.lua
@@ -4,7 +4,9 @@ require("luci.statistics.datatree")
require("luci.statistics.rrdtool.colors")
require("luci.statistics.rrdtool.definitions")
require("luci.statistics.i18n")
+require("luci.model.uci")
require("luci.util")
+require("luci.sys")
require("luci.fs")
@@ -14,16 +16,24 @@ function Graph.__init__( self, timespan, opts )
opts = opts or { }
+ local uci = luci.model.uci.Session()
+ local sections, names = uci:sections( "luci_statistics" )
+
+ -- helper classes
self.colors = luci.statistics.rrdtool.colors.Instance()
self.defs = luci.statistics.rrdtool.definitions.Instance()
self.tree = luci.statistics.datatree.Instance()
self.i18n = luci.statistics.i18n.Instance( self )
-- options
- opts.rrasingle = opts.rrasingle or true -- XXX: fixme (uci)
- opts.host = opts.host or "OpenWrt" -- XXX: fixme (uci)
- opts.timespan = opts.timespan or 900 -- XXX: fixme (uci)
- opts.width = opts.width or 400 -- XXX: fixme (uci)
+ 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"
+ opts.rrdpath = opts.rrdpath:gsub("/$","")
+ opts.imgpath = opts.imgpath:gsub("/$","")
-- rrdtool default args
self.args = {
@@ -49,11 +59,15 @@ function Graph._mkpath( self, plugin, plugin_instance, dtype, dtype_instance )
end
function Graph.mkrrdpath( self, ... )
- return string.format( "/tmp/%s.rrd", self:_mkpath( ... ) )
+ return string.format( "%s/%s.rrd", self.opts.rrdpath, self:_mkpath( ... ) )
end
function Graph.mkpngpath( self, ... )
- return string.format( "/tmp/rrdimg/%s.png", self:_mkpath( ... ) )
+ return string.format( "%s/%s.png", self.opts.imgpath, self:_mkpath( ... ) )
+end
+
+function Graph.strippngpath( self, path )
+ return path:sub( self.opts.imgpath:len() + 2 )
end
function Graph.mktitle( self, plugin, plugin_instance, dtype, dtype_instance )
diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/irq/irq.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/irq/irq.lua
new file mode 100644
index 000000000..a68227bf5
--- /dev/null
+++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/irq/irq.lua
@@ -0,0 +1,10 @@
+module("luci.statistics.rrdtool.definitions.irq.irq", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ data = {
+ types = { "irq" }
+ }
+ }
+end
diff --git a/applications/luci-statistics/luasrc/view/public_statistics/graph.htm b/applications/luci-statistics/luasrc/view/public_statistics/graph.htm
index 093d76d0e..effe0c401 100644
--- a/applications/luci-statistics/luasrc/view/public_statistics/graph.htm
+++ b/applications/luci-statistics/luasrc/view/public_statistics/graph.htm
@@ -3,7 +3,7 @@
<h1>Statistik</h1>
<% for i, img in ipairs(images) do %>
- <img src="<%=img:gsub("/tmp/rrdimg/OpenWrt","/img")%>" />
+ <img src="/img/<%=img%>" />
<% end %>
<%+footer%>