X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-statistics%2Fluasrc%2Fstatistics%2Frrdtool.lua;h=dbcae9dc6be42c79701c4a61662c0b6deac719f4;hp=eb5c266b0e5e478eabe7229741c1e28249453db5;hb=99a8b2826e15c08972dc34170f70b40abba5922e;hpb=8fcd841aa9af96c8a4a4d3c1a555d2d1ed42332c;ds=sidebyside diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-statistics/luasrc/statistics/rrdtool.lua index eb5c266b0..dbcae9dc6 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool.lua @@ -17,7 +17,6 @@ module("luci.statistics.rrdtool", package.seeall) 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") @@ -35,12 +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.defs = luci.statistics.rrdtool.definitions.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" ) @@ -51,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", @@ -158,11 +156,14 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) if not ds or ds:len() == 0 then ds = "value" end - _tif( _args, "DEF:%s_avg=%s:%s:AVERAGE", inst, rrd, ds ) + _tif( _args, "DEF:%s_avg_raw=%s:%s:AVERAGE", inst, rrd, ds ) + _tif( _args, "CDEF:%s_avg=%s_avg_raw,%s", inst, inst, source.transform_rpn ) 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 ) + _tif( _args, "DEF:%s_min_raw=%s:%s:MIN", inst, rrd, ds ) + _tif( _args, "CDEF:%s_min=%s_min_raw,%s", inst, inst, source.transform_rpn ) + _tif( _args, "DEF:%s_max_raw=%s:%s:MAX", inst, rrd, ds ) + _tif( _args, "CDEF:%s_max=%s_max_raw,%s", inst, inst, source.transform_rpn ) end _tif( _args, "CDEF:%s_nnl=%s_avg,UN,0,%s_avg,IF", inst, inst, inst ) @@ -182,20 +183,23 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) -- is first source in stack or overlay source: source_stk = source_nnl if not prev or source.overlay then - -- create cdef statement + -- create cdef statement for cumulative stack (no NaNs) and also + -- for display (preserving NaN where no points should be displayed) _tif( _args, "CDEF:%s_stk=%s_nnl", source.sname, source.sname ) + _tif( _args, "CDEF:%s_plot=%s_avg", source.sname, source.sname ) -- is subsequent source without overlay: source_stk = source_nnl + previous_stk else -- create cdef statement _tif( _args, "CDEF:%s_stk=%s_nnl,%s_stk,+", source.sname, source.sname, prev ) + _tif( _args, "CDEF:%s_plot=%s_avg,%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 - _tif( _args, "CDEF:%s_neg=%s_stk,-1,*", source.sname, source.sname ) + _tif( _args, "CDEF:%s_neg=%s_plot,-1,*", source.sname, source.sname ) -- push to negative stack if overlay is disabled if not source.overlay then @@ -255,11 +259,11 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) -- derive area background color from line color area_color = self.colors:to_string( self.colors:faded( area_color ) ) - -- choose source_stk or source_neg variable depending on flip state + -- choose source_plot or source_neg variable depending on flip state if source.flip then var = "neg" else - var = "stk" + var = "plot" end -- create legend @@ -271,7 +275,9 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) end -- create line1 statement - _tif( _args, "LINE1:%s_%s#%s:%s", source.sname, var, line_color, legend ) + _tif( _args, "LINE%d:%s_%s#%s:%s", + source.noarea and 2 or 1, + source.sname, var, line_color, legend ) end -- local helper: create gprint statements @@ -375,6 +381,8 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) local dsname = dtype .. "_" .. dinst:gsub("[^%w]","_") .. "_" .. dsource local altname = dtype .. "__" .. dsource + --assert(dtype ~= "ping", dsname .. " or " .. altname) + -- find datasource options local dopts = { } @@ -398,7 +406,9 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) flip = dopts.flip or false, total = dopts.total or false, overlay = dopts.overlay or false, + transform_rpn = dopts.transform_rpn or "0,+", noarea = dopts.noarea or false, + title = dopts.title or nil, ds = dsource, type = dtype, instance = dinst, @@ -444,9 +454,21 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) -- store title and vlabel _ti( _args, "-t" ) - _ti( _args, opts.title or self.i18n:title( plugin, plugin_instance, _sources[1].type, instance ) ) + _ti( _args, self.i18n:title( plugin, plugin_instance, _sources[1].type, instance, opts.title ) ) _ti( _args, "-v" ) - _ti( _args, opts.vlabel or self.i18n:label( plugin, plugin_instance, _sources[1].type, instance ) ) + _ti( _args, self.i18n:label( plugin, plugin_instance, _sources[1].type, instance, opts.vlabel ) ) + if opts.y_max then + _ti ( _args, "-u" ) + _ti ( _args, opts.y_max ) + end + if opts.y_min then + _ti ( _args, "-l" ) + _ti ( _args, opts.y_min ) + end + if opts.units_exponent then + _ti ( _args, "-X" ) + _ti ( _args, opts.units_exponent ) + end -- store additional rrd options if opts.rrdopts then @@ -494,7 +516,7 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) return defs end -function Graph.render( self, plugin, plugin_instance ) +function Graph.render( self, plugin, plugin_instance, is_index ) dtype_instances = dtype_instances or { "" } local pngs = { } @@ -509,21 +531,21 @@ function Graph.render( self, plugin, plugin_instance ) local _images = { } -- get diagram definitions - for i, opts in ipairs( self:_forcelol( def.rrdargs( self, plugin, plugin_instance ) ) ) do - - _images[i] = { } + for i, opts in ipairs( self:_forcelol( def.rrdargs( self, plugin, plugin_instance, nil, is_index ) ) ) do + if not is_index or not opts.detail then + _images[i] = { } - -- get diagram definition instances - local diagrams = self:_generic( opts, plugin, plugin_instance, nil, 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 + -- render all diagrams + for j, def in ipairs( diagrams ) do + -- remember image + _images[i][j] = def[1] - -- remember image - _images[i][j] = def[1] - - -- exec - self:_rrdtool( def ) + -- exec + self:_rrdtool( def ) + end end end @@ -533,75 +555,6 @@ function Graph.render( self, plugin, plugin_instance ) table.insert( pngs, _images[x][y] ) end end - else - - -- no graph handler, iterate over data types - for i, dtype in ipairs( self.tree:data_types( plugin, plugin_instance ) ) do - - -- check for data type handler - local dtype_def = plugin_def .. "." .. dtype - local stat, def = pcall( require, dtype_def ) - - if stat and def and type(def.rrdargs) == "function" then - - -- 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( def ) - end - end - - -- 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 - - -- no data type handler, fall back to builtin definition - if type(self.defs.definitions[dtype]) == "table" then - - -- iterate over data type instances - for i, inst in ipairs( self.tree:data_instances( plugin, plugin_instance, dtype ) ) do - - local title = self.i18n:title( plugin, plugin_instance, dtype, inst ) - local label = self.i18n:label( 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, "-v", label } - - for i, o in ipairs(self.defs.definitions[dtype]) do - -- XXX: this is a somewhat ugly hack to exclude min/max RRAs when rrasingle is on - if not ( self.opts.rrasingle and ( o:match("_min") or o:match("_max") ) ) then - table.insert( args, o ) - end - end - - -- remember image - table.insert( pngs, png ) - - -- exec - self:_rrdtool( args, rrd ) - end - end - end - end end return pngs