diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-05-28 17:51:15 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-05-28 17:51:15 +0000 |
commit | bb5ecfde728c8f2e503fc28780aada78301ba6e4 (patch) | |
tree | 349036a75af740e84f483a802fc691115013bff6 /applications/luci-statistics/luasrc/statistics | |
parent | 4365fbe2a373b73af5578d0ed6eddfb2ba9901ef (diff) |
* luci/statistics: implement a more advanced diagram generator in rrdtool.lua, simplified diagram models, fix bug in datatree.lua
Diffstat (limited to 'applications/luci-statistics/luasrc/statistics')
9 files changed, 625 insertions, 416 deletions
diff --git a/applications/luci-statistics/luasrc/statistics/datatree.lua b/applications/luci-statistics/luasrc/statistics/datatree.lua index 957b230a9..82e7a281d 100644 --- a/applications/luci-statistics/luasrc/statistics/datatree.lua +++ b/applications/luci-statistics/luasrc/statistics/datatree.lua @@ -123,11 +123,13 @@ function Instance.data_types( self, plugin, instance ) return rv end -function Instance.data_instances( self, plugin, instance, type ) +function Instance.data_instances( self, plugin, instance, dtype ) local rv = { } - for i, instance in ipairs( self._plugins[plugin][instance][type] ) do - table.insert( rv, instance ) + if type(self._plugins[plugin][instance][dtype]) == "table" then + for i, instance in ipairs( self._plugins[plugin][instance][dtype] ) do + table.insert( rv, instance ) + end end return rv diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-statistics/luasrc/statistics/rrdtool.lua index 783314e8c..17ac48a5a 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool.lua @@ -3,8 +3,8 @@ module("luci.statistics.rrdtool", package.seeall) require("luci.statistics.datatree") require("luci.statistics.rrdtool.colors") require("luci.statistics.rrdtool.definitions") +require("luci.i18n") require("luci.util") -require("luci.bits") require("luci.fs") @@ -13,22 +13,34 @@ Graph = luci.util.class() function Graph.__init__( self, timespan, opts ) opts = opts or { } - opts.width = opts.width or "400" self.colors = luci.statistics.rrdtool.colors.Instance() self.defs = luci.statistics.rrdtool.definitions.Instance() self.tree = luci.statistics.datatree.Instance() + self.i18n = luci.i18n - -- rrdtool defalt args - self.args = { + -- 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) + + -- rrdtool default args + self.args = { "-a", "PNG", - "-s", "NOW-" .. ( timespan or 900 ), + "-s", "NOW-" .. opts.timespan, "-w", opts.width } + + -- store options + self.opts = opts + + -- load language file + self.i18n.loadc("statistics") end -function Graph.mktitle( self, host, plugin, plugin_instance, dtype, dtype_instance ) - local t = host .. "/" .. plugin +function Graph.mktitle( self, plugin, plugin_instance, dtype, dtype_instance ) + local t = self.opts.host .. "/" .. plugin if type(plugin_instance) == "string" and plugin_instance:len() > 0 then t = t .. "-" .. plugin_instance end @@ -47,25 +59,6 @@ function Graph.mkpngpath( self, ... ) return string.format( "/tmp/rrdimg/%s.png", self:mktitle( ... ) ) end -function Graph._push( self, elem ) - - if type(elem) == "string" then - table.insert( self.args, elem ) - else - for i, item in ipairs(elem) do - table.insert( self.args, item ) - end - end - - return( self.args ) -end - -function Graph._clearargs( self ) - for i = #self.args, 7, -1 do - table.remove( self.args, i ) - end -end - function Graph._forcelol( self, list ) if type(list[1]) ~= "table" then return( { list } ) @@ -73,17 +66,22 @@ function Graph._forcelol( self, list ) return( list ) end -function Graph._rrdtool( self, png, rrd ) +function Graph._rrdtool( self, def, rrd ) -- prepare directory - local dir = png:gsub("/[^/]+$","") + local dir = def[1]:gsub("/[^/]+$","") luci.fs.mkdir( dir, true ) -- construct commandline - local cmdline = "rrdtool graph " .. png + local cmdline = "rrdtool graph" + -- copy default arguments to def stack for i, opt in ipairs(self.args) do + table.insert( def, 1 + i, opt ) + end + -- construct commandline from def stack + for i, opt in ipairs(def) do opt = opt .. "" -- force string if rrd then @@ -102,12 +100,14 @@ function Graph._rrdtool( self, png, rrd ) rrdtool:close() end -function Graph._generic( self, opts ) +function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) - local images = { } - local rrasingle = false -- XXX: fixme + -- generated graph defs + local defs = { } -- internal state variables + local _args = { } + local _sources = { } local _stack_neg = { } local _stack_pos = { } local _longest_name = 0 @@ -117,6 +117,11 @@ function Graph._generic( self, opts ) local _ti = table.insert local _sf = string.format + -- local helper: append a string.format() formatted string to given table + function _tif( list, fmt, ... ) + table.insert( list, string.format( fmt, ... ) ) + end + -- local helper: create definitions for min, max, avg and create *_nnl (not null) variable from avg function __def(source) @@ -126,22 +131,19 @@ function Graph._generic( self, opts ) if not ds or ds:len() == 0 then ds = "value" end - local rv = { _sf( "DEF:%s_avg=%s:%s:AVERAGE", inst, rrd, ds ) } + _tif( _args, "DEF:%s_avg=%s:%s:AVERAGE", inst, rrd, ds ) - if not rrasingle then - _ti( rv, _sf( "DEF:%s_min=%s:%s:MIN", inst, rrd, ds ) ) - _ti( rv, _sf( "DEF:%s_max=%s:%s:MAX", inst, rrd, ds ) ) + if not self.opts.rrasingle then + _tif( _args, "DEF:%s_min=%s:%s:MIN", inst, rrd, ds ) + _tif( _args, "DEF:%s_max=%s:%s:MAX", inst, rrd, ds ) end - _ti( rv, _sf( "CDEF:%s_nnl=%s_avg,UN,0,%s_avg,IF", inst, inst, inst ) ) - - return rv + _tif( _args, "CDEF:%s_nnl=%s_avg,UN,0,%s_avg,IF", inst, inst, inst ) end -- local helper: create cdefs depending on source options like flip and overlay function __cdef(source) - local rv = { } local prev -- find previous source, choose stack depending on flip state @@ -154,21 +156,19 @@ function Graph._generic( self, opts ) -- is first source in stack or overlay source: source_stk = source_nnl if not prev or source.overlay then -- create cdef statement - _ti( rv, _sf( "CDEF:%s_stk=%s_nnl", source.sname, source.sname ) ) + _tif( _args, "CDEF:%s_stk=%s_nnl", source.sname, source.sname ) -- is subsequent source without overlay: source_stk = source_nnl + previous_stk else -- create cdef statement - _ti( rv, _sf( - "CDEF:%s_stk=%s_nnl,%s_stk,+", source.sname, source.sname, prev - ) ) + _tif( _args, "CDEF:%s_stk=%s_nnl,%s_stk,+", source.sname, source.sname, prev ) end -- create multiply by minus one cdef if flip is enabled if source.flip then -- create cdef statement: source_stk = source_stk * -1 - _ti( rv, _sf( "CDEF:%s_neg=%s_stk,-1,*", source.sname, source.sname ) ) + _tif( _args, "CDEF:%s_neg=%s_stk,-1,*", source.sname, source.sname ) -- push to negative stack if overlay is disabled if not source.overlay then @@ -184,36 +184,29 @@ function Graph._generic( self, opts ) -- calculate total amount of data if requested if source.total then - _ti( rv, _sf( + _tif( _args, "CDEF:%s_avg_sample=%s_avg,UN,0,%s_avg,IF,sample_len,*", source.sname, source.sname, source.sname - ) ) + ) - _ti( rv, _sf( + _tif( _args, "CDEF:%s_avg_sum=PREV,UN,0,PREV,IF,%s_avg_sample,+", source.sname, source.sname, source.sname - ) ) + ) end - - - return rv end -- local helper: create cdefs required for calculating total values function __cdef_totals() if _has_totals then - return { - _sf( "CDEF:mytime=%s_avg,TIME,TIME,IF", opts.sources[1].sname ), - "CDEF:sample_len_raw=mytime,PREV(mytime),-", - "CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF" - } - else - return { } + _tif( _args, "CDEF:mytime=%s_avg,TIME,TIME,IF", _sources[1].sname ) + _ti( _args, "CDEF:sample_len_raw=mytime,PREV(mytime),-" ) + _ti( _args, "CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF" ) end end -- local helper: create line and area statements - function __area(source) + function __line(source) local line_color local area_color @@ -243,96 +236,236 @@ function Graph._generic( self, opts ) end -- create legend - legend = _sf( "%-" .. _longest_name .. "s", source.name ) + legend = _sf( "%-" .. _longest_name .. "s", source.title ) + + -- create area if not disabled + if not source.noarea then + _tif( _args, "AREA:%s_%s#%s", source.sname, var, area_color ) + end - -- create area and line1 statement - return { - _sf( "AREA:%s_%s#%s", source.sname, var, area_color ), - _sf( "LINE1:%s_%s#%s:%s", source.sname, var, line_color, legend ) - } + -- create line1 statement + _tif( _args, "LINE1:%s_%s#%s:%s", source.sname, var, line_color, legend ) end -- local helper: create gprint statements function __gprint(source) - local rv = { } local numfmt = opts.number_format or "%6.1lf" local totfmt = opts.totals_format or "%5.1lf%s" -- don't include MIN if rrasingle is enabled - if not rrasingle then - _ti( rv, _sf( "GPRINT:%s_min:MIN:%s Min", source.sname, numfmt ) ) + if not self.opts.rrasingle then + _tif( _args, "GPRINT:%s_min:MIN:%s Min", source.sname, numfmt ) end -- always include AVERAGE - _ti( rv, _sf( "GPRINT:%s_avg:AVERAGE:%s Avg", source.sname, numfmt ) ) + _tif( _args, "GPRINT:%s_avg:AVERAGE:%s Avg", source.sname, numfmt ) -- don't include MAX if rrasingle is enabled - if not rrasingle then - _ti( rv, _sf( "GPRINT:%s_max:MAX:%s Max", source.sname, numfmt ) ) + if not self.opts.rrasingle then + _tif( _args, "GPRINT:%s_max:MAX:%s Max", source.sname, numfmt ) end -- include total count if requested else include LAST if source.total then - _ti( rv, _sf( "GPRINT:%s_avg_sum:LAST:(ca. %s Total)", source.sname, totfmt ) ) + _tif( _args, "GPRINT:%s_avg_sum:LAST:(ca. %s Total)\\l", source.sname, totfmt ) else - _ti( rv, _sf( "GPRINT:%s_avg:LAST:%s Last", source.sname, numfmt ) ) + _tif( _args, "GPRINT:%s_avg:LAST:%s Last\\l", source.sname, numfmt ) end + end + - -- end label line - rv[#rv] = rv[#rv] .. "\\l" + -- + -- find all data sources + -- + -- find data types + local data_types - return rv + if dtype then + data_types = { dtype } + else + data_types = opts.data.types or { } end + if not ( dtype or opts.data.types ) then + if opts.data.instances then + for k, v in pairs(opts.data.instances) do + _ti( data_types, k ) + end + elseif opts.data.sources then + for k, v in pairs(opts.data.sources) do + _ti( data_types, k ) + end + end + end - -- remember images - _ti( images, opts.image ) - -- insert provided addition rrd options - self:_push( { "-t", opts.title or "Unknown title" } ) - self:_push( opts.rrd ) + -- iterate over data types + for i, dtype in ipairs(data_types) do - -- store index and safe instance name within each source object, - -- find longest instance name - for i, source in ipairs(opts.sources) do + -- find instances - if source.name:len() > _longest_name then - _longest_name = source.name:len() - end + local data_instances - if source.total then - _has_totals = true + if not opts.per_instance then + if type(opts.data.instances) == "table" and type(opts.data.instances[dtype]) == "table" then + data_instances = opts.data.instances[dtype] + else + data_instances = self.tree:data_instances( plugin, plugin_instance, dtype ) + end end - source.index = i - source.sname = i .. source.name:gsub("[^A-Za-z0-9%-_]","_") - end + if type(data_instances) ~= "table" or #data_instances == 0 then data_instances = { "" } end + + + -- iterate over data instances + for i, dinst in ipairs(data_instances) do + + -- construct combined data type / instance name + local dname = dtype - -- create DEF statements for each instance, find longest instance name - for i, source in ipairs(opts.sources) do - self:_push( __def( source ) ) + if dinst:len() > 0 then + dname = dname .. "_" .. dinst + end + + + -- find sources + local data_sources = { "value" } + + if type(opts.data.sources) == "table" then + if type(opts.data.sources[dname]) == "table" then + data_sources = opts.data.sources[dname] + elseif type(opts.data.sources[dtype]) == "table" then + data_sources = opts.data.sources[dtype] + end + end + + + -- iterate over data sources + for i, dsource in ipairs(data_sources) do + + local dsname = dtype .. "_" .. dinst:gsub("[^%w]","_") .. "_" .. dsource + local altname = dtype .. "__" .. dsource + + -- find datasource options + local dopts = { } + + if type(opts.data.options) == "table" then + if type(opts.data.options[dsname]) == "table" then + dopts = opts.data.options[dsname] + elseif type(opts.data.options[altname]) == "table" then + dopts = opts.data.options[altname] + elseif type(opts.data.options[dname]) == "table" then + dopts = opts.data.options[dname] + elseif type(opts.data.options[dtype]) == "table" then + dopts = opts.data.options[dtype] + end + end + + + -- store values + _ti( _sources, { + title = dsname, -- XXX: fixme i18n (dopts.title || i18n || dname) + rrd = dopts.rrd or self:mkrrdpath( plugin, plugin_instance, dtype, dinst ), + color = dopts.color or self.colors:to_string( self.colors:random() ), + flip = dopts.flip or false, + total = dopts.total or false, + overlay = dopts.overlay or false, + noarea = dopts.noarea or false, + ds = dsource, + type = dtype, + instance = dinst, + index = #_sources + 1, + sname = ( #_sources + 1 ) .. dtype + } ) + + + -- find longest name ... + if _sources[#_sources].title:len() > _longest_name then + _longest_name = _sources[#_sources].title:len() + end + + + -- has totals? + if _sources[#_sources].total then + _has_totals = true + end + end + end end - -- create CDEF required for calculating totals - self:_push( __cdef_totals() ) - -- create CDEF statements for each instance in reversed order - for i, source in ipairs(opts.sources) do - self:_push( __cdef( opts.sources[1 + #opts.sources - i] ) ) + -- + -- construct diagrams + -- + + -- if per_instance is enabled then find all instances from the first datasource in diagram + -- if per_instance is disabled then use an empty pseudo instance and use model provided values + local instances = { "" } + + if opts.per_instance then + instances = self.tree:data_instances( plugin, plugin_instance, _sources[1].type ) end - -- create LINE1, AREA and GPRINT statements for each instance - for i, source in ipairs(opts.sources) do - self:_push( __area( source ) ) - self:_push( __gprint( source ) ) + + -- iterate over instances + for i, instance in ipairs(instances) do + + -- store title and vlabel + -- XXX: i18n + _ti( _args, "-t" ) + _ti( _args, opts.title ) + _ti( _args, "-v" ) + _ti( _args, opts.vlabel ) + + -- store additional rrd options + if opts.rrdopts then + for i, o in ipairs(opts.rrdopts) do _ti( _args, o ) end + end + + + -- create DEF statements for each instance + for i, source in ipairs(_sources) do + -- fixup properties for per instance mode... + if opts.per_instance then + source.instance = instance + source.rrd = self:mkrrdpath( plugin, plugin_instance, source.type, instance ) + end + + __def( source ) + end + + -- create CDEF required for calculating totals + __cdef_totals() + + -- create CDEF statements for each instance in reversed order + for i, source in ipairs(_sources) do + __cdef( _sources[1 + #_sources - i] ) + end + + -- create LINE1, AREA and GPRINT statements for each instance + for i, source in ipairs(_sources) do + __line( source ) + __gprint( source ) + end + + -- prepend image path to arg stack + _ti( _args, 1, self:mkpngpath( plugin, plugin_instance, index .. instance ) ) + + -- push arg stack to definition list + _ti( defs, _args ) + + -- reset stacks + _args = { } + _stack_pos = { } + _stack_neg = { } end - return images + return defs end -function Graph.render( self, host, plugin, plugin_instance ) +function Graph.render( self, plugin, plugin_instance ) dtype_instances = dtype_instances or { "" } local pngs = { } @@ -342,15 +475,33 @@ function Graph.render( self, host, plugin, plugin_instance ) local stat, def = pcall( require, plugin_def ) if stat and def and type(def.rrdargs) == "function" then - for i, opts in ipairs( self:_forcelol( def.rrdargs( self, host, plugin, plugin_instance, dtype ) ) ) do - for i, png in ipairs( self:_generic( opts ) ) do - table.insert( pngs, png ) + + -- temporary image matrix + local _images = { } + + -- get diagram definitions + for i, opts in ipairs( self:_forcelol( def.rrdargs( self, plugin, plugin_instance ) ) ) do + + _images[i] = { } + + -- get diagram definition instances + local diagrams = self:_generic( opts, plugin, plugin_instance, nil, i ) + + -- render all diagrams + for j, def in ipairs( diagrams ) do + + -- remember image + _images[i][j] = def[1] -- exec - self:_rrdtool( png ) + self:_rrdtool( def ) + end + end - -- clear args - self:_clearargs() + -- remember images - XXX: fixme (will cause probs with asymmetric data) + for y = 1, #_images[1] do + for x = 1, #_images do + table.insert( pngs, _images[x][y] ) end end else @@ -363,15 +514,33 @@ function Graph.render( self, host, plugin, plugin_instance ) local stat, def = pcall( require, dtype_def ) if stat and def and type(def.rrdargs) == "function" then - for i, opts in ipairs( self:_forcelol( def.rrdargs( self, host, plugin, plugin_instance, dtype ) ) ) do - for i, png in ipairs( self:_generic( opts ) ) do - table.insert( pngs, png ) + + -- temporary image matrix + local _images = { } + + -- get diagram definitions + for i, opts in ipairs( self:_forcelol( def.rrdargs( self, plugin, plugin_instance, dtype ) ) ) do + + _images[i] = { } + + -- get diagram definition instances + local diagrams = self:_generic( opts, plugin, plugin_instance, dtype, i ) + + -- render all diagrams + for j, def in ipairs( diagrams ) do + + -- remember image + _images[i][j] = def[1] -- exec - self:_rrdtool( png ) + self:_rrdtool( def ) + end + end - -- clear args - self:_clearargs() + -- remember images - XXX: fixme (will cause probs with asymmetric data) + for y = 1, #_images[1] do + for x = 1, #_images do + table.insert( pngs, _images[x][y] ) end end else @@ -382,20 +551,20 @@ function Graph.render( self, host, plugin, plugin_instance ) -- iterate over data type instances for i, inst in ipairs( self.tree:data_instances( plugin, plugin_instance, dtype ) ) do - local title = self:mktitle( host, plugin, plugin_instance, dtype, inst ) - local png = self:mkpngpath( host, plugin, plugin_instance, dtype, inst ) - local rrd = self:mkrrdpath( host, plugin, plugin_instance, dtype, inst ) - - self:_push( { "-t", title } ) - self:_push( self.defs.definitions[dtype] ) + local title = self:mktitle( plugin, plugin_instance, dtype, inst ) + 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 + -- remember image table.insert( pngs, png ) -- exec - self:_rrdtool( png, rrd ) - - -- clear args - self:_clearargs() + self:_rrdtool( args, rrd ) end end end @@ -404,4 +573,3 @@ function Graph.render( self, host, plugin, plugin_instance ) return pngs end - diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua index 2626d276d..5a2ac53ca 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua @@ -2,30 +2,25 @@ module("luci.statistics.rrdtool.definitions.cpu.cpu",package.seeall) function rrdargs( graph, host, plugin, plugin_instance, dtype ) - dtype_instances = { "idle", "nice", "system", "user" } + return { + title = "Prozessorauslastung", + vlabel = "%", - opts = { } - opts.sources = { } - opts.image = graph:mkpngpath( host, plugin, plugin_instance, dtype ) - opts.title = host .. ": Prozessorauslastung" - opts.rrd = { "-v", "Percent" } - opts.colors = { - idle = 'ffffff', - nice = '00e000', - user = '0000ff', - wait = 'ffb000', - system = 'ff0000', - softirq = 'ff00ff', - interrupt = 'a000a0', - steal = '000000' - } + data = { + instances = { + cpu = { "idle", "nice", "system", "user" } + }, - for i, inst in ipairs(dtype_instances) do - opts.sources[i] = { - name = inst, - rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ) + options = { + cpu_idle = { color = "ffffff" }, + cpu_nice = { color = "00e000" }, + cpu_user = { color = "0000ff" }, + cpu_wait = { color = "ffb000" }, + cpu_system = { color = "ff0000" }, + cpu_softirq = { color = "ff00ff" }, + cpu_interrupt = { color = "a000a0" }, + cpu_steal = { color = "000000" } + } } - end - - return opts + } end diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua index b16add995..455107322 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua @@ -1,26 +1,15 @@ module("luci.statistics.rrdtool.definitions.iptables.ipt_packets", package.seeall) -function rrdargs( graph, host, plugin, plugin_instance, dtype ) +function rrdargs( graph, plugin, plugin_instance, dtype ) - dtype_instances = graph.tree:data_instances( plugin, plugin_instance, dtype ) - opts = { } - - for i, inst in ipairs(dtype_instances) do - - opts[i] = { } - opts[i].image = graph:mkpngpath( host, plugin, plugin_instance, dtype, inst ) - opts[i].title = host .. ": Firewall - " .. inst:gsub("_"," ") - opts[i].rrd = { "-v", "Pakete/s" } - - opts[i].colors = { + return { + title = "Firewall", + vlabel = "Pakete/s", + data = { + options = { + ipt_packets = { total = true } + } } - - opts[i].sources = { { - name = inst, - rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ) - } } - end - - return opts + } end diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua index 3960b9c53..47594f0f8 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua @@ -1,180 +1,208 @@ module("luci.statistics.rrdtool.definitions.netlink", package.seeall) -function rrdargs( graph, host, plugin, plugin_instance ) - - local diagram_list = { } - - -- diagram names - local dtypes_names = { - "Verkehr", - "Pakete", - "Multicast-Pakete", - "Paketkollisionen", - "Paketfehler", - "RX-Fehler", - "TX-Fehler" +function rrdargs( graph, plugin, plugin_instance ) + + -- + -- traffic diagram + -- + local traffic = { + + -- diagram title + title = "Verkehr", + + -- vertical label + vlabel = "Bytes/s", + + -- diagram data description + data = { + -- defined sources for data types, if ommitted assume a single DS named "value" (optional) + sources = { + if_octets = { "tx", "rx" } + }, + + -- special options for single data lines + options = { + if_octets__tx = { + total = true, -- report total amount of bytes + color = "00ff00" -- tx is green + }, + + if_octets__rx = { + flip = true, -- flip rx line + total = true, -- report total amount of bytes + color = "0000ff" -- rx is blue + } + } + } } - -- diagram units - local dtypes_units = { - "Bytes/s", - "Pakete/s", - "Pakete/s", - "Kollisionen/s", - "Fehler/s", -- (?) - "Fehler/s", - "Fehler/s" - } - -- data source overrides - local dtypes_sources = { - if_errors = { "tx", "rx" }, -- if_errors has tx and rx - if_octets = { "tx", "rx" }, -- if_octets has tx and rx - if_packets = { "tx", "rx" }, -- if_packets has tx and rx - if_dropped = { "tx", "rx" }, -- if_dopped has tx and rx + -- + -- packet diagram + -- + local packets = { + + -- diagram title + title = "Pakete", + + -- vertical label + vlabel = "Pakete/s", + + -- diagram data description + data = { + -- data type order + types = { "if_packets", "if_dropped", "if_errors" }, + + -- defined sources for data types + sources = { + if_packets = { "tx", "rx" }, + if_dropped = { "tx", "rx" }, + if_errors = { "tx", "rx" } + }, + + -- special options for single data lines + options = { + -- processed packets (tx DS) + if_packets__tx = { + overlay = true, -- don't summarize + total = true, -- report total amount of bytes + color = "00ff00" -- processed tx is green + }, + + -- processed packets (rx DS) + if_packets__rx = { + overlay = true, -- don't summarize + flip = true, -- flip rx line + total = true, -- report total amount of bytes + color = "0000ff" -- processed rx is blue + }, + + -- dropped packets (tx DS) + if_dropped__tx = { + overlay = true, -- don't summarize + total = true, -- report total amount of bytes + color = "660055" -- dropped tx is ... dunno ;) + }, + + -- dropped packets (rx DS) + if_dropped__rx = { + overlay = true, -- don't summarize + flip = true, -- flip rx line + total = true, -- report total amount of bytes + color = "440066" -- dropped rx is violett + }, + + -- packet errors (tx DS) + if_errors__tx = { + overlay = true, -- don't summarize + total = true, -- report total amount of packets + color = "ff5500" -- tx errors are orange + }, + + -- packet errors (rx DS) + if_errors__rx = { + overlay = true, -- don't summarize + flip = true, -- flip rx line + total = true, -- report total amount of packets + color = "ff0000" -- rx errors are red + } + } + } } - -- diagram data types - local dtypes_list = { - - -- diagram 1: interface traffic statistics - { - if_octets = { "" } -- bytes/s - }, - - -- diagram 2: combined interface packet statistics - { - if_dropped = { "" }, -- packets/s - if_packets = { "" } -- packets/s - }, - - -- diagram 3: multicast count - { - if_multicast = { "" } -- packets/s - }, - - -- diagram 4: interface collision statistics - { - if_collisions = { "" } -- collisions/s - }, - - -- diagram 5: interface error statistics - { - if_errors = { "" } -- errors/s (?) - }, - - -- diagram 6: interface rx error statistics - { - if_rx_errors = { -- errors/s - "length", "missed", "over", "crc", "fifo", "frame" + + -- + -- multicast diagram + -- + local multicast = { + + -- diagram title + title = "Multicast-Pakete", + + -- vertical label + vlabel = "Pakete/s", + + -- diagram data description + data = { + -- data type order + types = { "if_multicast" }, + + -- special options for single data lines + options = { + -- multicast packets + if_multicast = { + total = true, -- report total amount of packets + color = "0000ff" -- multicast is blue + } } - }, + } + } + - -- diagram 7: interface tx error statistics - { - if_tx_errors = { -- errors/s - "aborted", "carrier", "fifo", "heartbeat", "window" + -- + -- collision diagram + -- + local collisions = { + + -- diagram title + title = "Paketkollisionen", + + -- vertical label + vlabel = "Kollisionen/s", + + -- diagram data description + data = { + -- data type order + types = { "if_collisions" }, + + -- special options for single data lines + options = { + -- collision rate + if_collisions = { + total = true, -- report total amount of packets + color = "ff0000" -- collsions are red + } } } } - -- diagram colors - local dtypes_colors = { - - -- diagram 1 - { - if_octets__tx_ = "00ff00", - if_octets__rx_ = "0000ff" - }, - - -- diagram 2 - { - if_dropped__tx_ = "ff0000", - if_dropped__rx_ = "ff5500", - if_packets__tx_ = "00ff00", - if_packets__rx_ = "0000ff" - }, - - -- diagram 3 - { - if_multicast = "0000ff" - }, - - -- diagram 4 - { - if_collisions = "ff0000" - }, - - -- diagram 5 - { - if_errors__tx_ = "ff0000", - if_errors__rx_ = "ff5500" - }, - - -- diagram 6 - { - length = "0000ff", - missed = "ff5500", - over = "ff0066", - crc = "ff0000", - fifo = "00ff00", - frame = "ffff00" - }, - - -- diagram 7 - { - aborted = "ff0000", - carrier = "ffff00", - fifo = "00ff00", - heartbeat = "0000ff", - window = "8800ff" + + -- + -- error diagram + -- + local errors = { + + -- diagram title + title = "TX/RX-Fehler", + + -- vertical label + vlabel = "Kollisionen/s", + + -- diagram data description + data = { + -- data type order + types = { "if_tx_errors", "if_rx_errors" }, + + -- data type instances + instances = { + if_tx_errors = { "aborted", "carrier", "fifo", "heartbeat", "window" }, + if_rx_errors = { "length", "missed", "over", "crc", "fifo", "frame" } + }, + + -- special options for single data lines + options = { -- XXX: fixme (define colors...) + if_tx_errors = { + total = true + }, + + if_rx_errors = { + flip = true, + total = true + } + } } } - for i, name in ipairs(dtypes_names) do - - local dtypes = dtypes_list[i] - local opts = { } - - opts.sources = { } - opts.image = graph:mkpngpath( host, plugin, plugin_instance, "netlink" .. i ) - opts.title = host .. ": Netlink Statistiken - " .. name .. " auf " .. plugin_instance - opts.rrd = { "-v", dtypes_units[i] } - opts.colors = dtypes_colors[i] - - for dtype, dinstances in pairs(dtypes) do - for i, inst in ipairs(dinstances) do - - local name = inst - if name:len() == 0 then name = dtype end - - -- check for data source override - if dtypes_sources[dtype] then - - -- has override - for i, ds in ipairs(dtypes_sources[dtype]) do - table.insert( opts.sources, { - ds = ds, -- override - name = name .. " (" .. ds .. ")", - rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ), - flip = ( ds == "rx" ), - total = ( ds == "rx" or ds == "tx" ) - } ) - end - else - -- no override, assume single "value" data source - table.insert( opts.sources, { - name = name, - rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ), - total = ( name == "if_multicast" ) - } ) - end - end - end - - table.insert( diagram_list, opts ) - end - - return diagram_list + return { traffic, packets, multicast, collisions, errors } end diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua index b041c015d..cf1db00b4 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua @@ -1,23 +1,15 @@ module("luci.statistics.rrdtool.definitions.ping.ping", package.seeall) -function rrdargs( graph, host, plugin, plugin_instance, dtype ) +function rrdargs( graph, plugin, plugin_instance, dtype ) - dtype_instances = graph.tree:data_instances( plugin, plugin_instance, dtype ) + return { + title = "Pingzeiten", + vlabel = "ms", - opts = { } - opts.sources = { } - opts.image = graph:mkpngpath( host, plugin, plugin_instance, dtype ) - opts.title = host .. ": Pingzeiten" - opts.rrd = { "-v", "Millisekunden" } - opts.colors = { } - - for i, inst in ipairs(dtype_instances) do - opts.sources[i] = { - ds = "ping", - name = inst, - rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ) + data = { + sources = { + ping = { "ping" } + } } - end - - return opts + } end diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua index 07cbe1d4a..715d19c76 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua @@ -1,31 +1,26 @@ module("luci.statistics.rrdtool.definitions.processes.ps_state", package.seeall) -function rrdargs( graph, host, plugin, plugin_instance, dtype ) +function rrdargs( graph, plugin, plugin_instance, dtype ) - dtype_instances = { - "sleeping", "running", "paging", "blocked", "stopped", "zombies" - } + return { + title = "Prozesse", + vlabel = "Anzahl/s", - opts = { } - opts.sources = { } - opts.image = graph:mkpngpath( host, plugin, plugin_instance, dtype ) - opts.title = host .. ": Prozesse" - opts.rrd = { "-v", "Anzahl" } - opts.colors = { - sleeping = "008080", - running = "008000", - paging = "ffff00", - blocked = "ff5000", - stopped = "555555", - zombies = "ff0000" - } + data = { + instances = { + ps_state = { + "sleeping", "running", "paging", "blocked", "stopped", "zombies" + } + }, - for i, inst in ipairs(dtype_instances) do - opts.sources[i] = { - name = inst, - rrd = graph:mkrrdpath( host, plugin, plugin_instance, "ps_state", inst ) + options = { + ps_state_sleeping = { color = "0000ff" }, + ps_state_running = { color = "008000" }, + ps_state_paging = { color = "ffff00" }, + ps_state_blocked = { color = "ff5000" }, + ps_state_stopped = { color = "555555" }, + ps_state_zombies = { color = "ff0000" } + } } - end - - return opts + } end diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua index 049357494..c944d990d 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua @@ -1,27 +1,25 @@ module("luci.statistics.rrdtool.definitions.tcpconns.tcp_connections", package.seeall) -function rrdargs( graph, host, plugin, plugin_instance, dtype ) +function rrdargs( graph, plugin, plugin_instance, dtype ) - dtype_instances = { - "SYN_SENT", "SYN_RECV", "LISTEN", "ESTABLISHED", "LAST_ACK", "TIME_WAIT", - "CLOSING", "CLOSE_WAIT", "CLOSED", "FIN_WAIT1", "FIN_WAIT2" - } - - opts = { } - opts.sources = { } - opts.image = graph:mkpngpath( host, plugin, plugin_instance, dtype ) - opts.title = host .. ": TCP-Verbindungen - Port " .. plugin_instance - opts.rrd = { "-v", "Anzahl" } - opts.colors = { + return { + title = "TCP-Verbindungen auf Port " .. plugin_instance, + vlabel = "Anzahl/s", - } + data = { + instances = { + tcp_connections = { + "SYN_SENT", "SYN_RECV", "LISTEN", "ESTABLISHED", + "LAST_ACK", "TIME_WAIT", "CLOSING", "CLOSE_WAIT", + "CLOSED", "FIN_WAIT1", "FIN_WAIT2" + } + }, - for i, inst in ipairs(dtype_instances) do - opts.sources[i] = { - name = inst, - rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ) + options = { + tcp_connections = { + total = true + } + } } - end - - return opts + } end diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua index 708aee311..6c68bb269 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua @@ -2,25 +2,67 @@ module("luci.statistics.rrdtool.definitions.wireless", package.seeall) function rrdargs( graph, host, plugin, plugin_instance ) - dtypes = { "signal_noise", "signal_power" } - - opts = { } - opts.sources = { } - opts.image = graph:mkpngpath( host, plugin, plugin_instance, "wireless" ) - opts.title = host .. ": WLAN Signal" - opts.rrd = { "-v", "dBm" } - opts.colors = { - signal_power = '0000ff', - signal_noise = 'ff0000' + -- + -- signal/noise diagram + -- + local snr = { + + -- diagram title + title = "Signal / Noise", + + -- vertical label + vlabel = "dBm", + + -- draw this diagram for each data instance + per_instance = true, + + -- diagram data description + data = { + types = { "signal_noise", "signal_power" }, + + -- special options for single data lines + options = { + signal_power = { + overlay = true, -- don't summarize + color = "0000ff" -- power is blue + }, + + signal_noise = { + overlay = true, -- don't summarize + color = "ff0000" -- noise is red + } + } + } } - for i, dtype in ipairs(dtypes) do - opts.sources[i] = { - name = dtype, - rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype ), - overlay = true -- don't summarize values + + -- + -- signal quality diagram + -- + local quality = { + + -- diagram title + title = "Signalqualitaet", + + -- vertical label + vlabel = "n/5", + + -- draw this diagram for each data instance + per_instance = true, + + -- diagram data description + data = { + types = { "signal_quality" }, + + -- special options for single data lines + options = { + signal_quality = { + noarea = true, -- don't draw area + color = "0000ff" -- quality is blue + } + } } - end + } - return opts + return { snr, quality } end |