Changeset 7980

Show
Ignore:
Timestamp:
11/28/11 04:24:37 (19 months ago)
Author:
jow
Message:

applications/luci-statistics: remove support for per-datatype models and builtin definitions, drop dependency on definitions.lua, support user provided title for datasources

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/applications/luci-statistics/luasrc/statistics/rrdtool.lua

    r5104 r7980  
    1818require("luci.statistics.datatree") 
    1919require("luci.statistics.rrdtool.colors") 
    20 require("luci.statistics.rrdtool.definitions") 
    2120require("luci.statistics.i18n") 
    2221require("luci.model.uci") 
     
    3837    -- helper classes 
    3938    self.colors = luci.statistics.rrdtool.colors.Instance() 
    40     self.defs   = luci.statistics.rrdtool.definitions.Instance() 
    4139    self.tree   = luci.statistics.datatree.Instance() 
    4240    self.i18n   = luci.statistics.i18n.Instance( self ) 
     
    272270 
    273271        -- create line1 statement 
    274         _tif( _args, "LINE1:%s_%s#%s:%s", source.sname, var, line_color, legend ) 
     272        _tif( _args, "LINE%d:%s_%s#%s:%s", 
     273            source.noarea and 2 or 1, 
     274            source.sname, var, line_color, legend ) 
    275275    end 
    276276 
     
    375375                local dsname  = dtype .. "_" .. dinst:gsub("[^%w]","_") .. "_" .. dsource 
    376376                local altname = dtype .. "__" .. dsource 
     377 
     378                --assert(dtype ~= "ping", dsname .. " or " .. altname) 
    377379 
    378380                -- find datasource options 
     
    400402                    overlay  = dopts.overlay or false, 
    401403                    noarea   = dopts.noarea  or false, 
     404                    title    = dopts.title   or nil, 
    402405                    ds       = dsource, 
    403406                    type     = dtype, 
     
    445448        -- store title and vlabel 
    446449        _ti( _args, "-t" ) 
    447         _ti( _args, opts.title  or self.i18n:title( plugin, plugin_instance, _sources[1].type, instance ) ) 
     450        _ti( _args, self.i18n:title( plugin, plugin_instance, _sources[1].type, instance, opts.title ) ) 
    448451        _ti( _args, "-v" ) 
    449         _ti( _args, opts.vlabel or self.i18n:label( plugin, plugin_instance, _sources[1].type, instance ) ) 
     452        _ti( _args, self.i18n:label( plugin, plugin_instance, _sources[1].type, instance, opts.vlabel ) ) 
    450453 
    451454        -- store additional rrd options 
     
    495498end 
    496499 
    497 function Graph.render( self, plugin, plugin_instance ) 
     500function Graph.render( self, plugin, plugin_instance, is_index ) 
    498501 
    499502    dtype_instances = dtype_instances or { "" } 
     
    510513 
    511514        -- get diagram definitions 
    512         for i, opts in ipairs( self:_forcelol( def.rrdargs( self, plugin, plugin_instance ) ) ) do 
     515        for i, opts in ipairs( self:_forcelol( def.rrdargs( self, plugin, plugin_instance, nil, is_index ) ) ) do 
    513516 
    514517            _images[i] = { } 
     
    534537            end 
    535538        end 
    536     else 
    537  
    538         -- no graph handler, iterate over data types 
    539         for i, dtype in ipairs( self.tree:data_types( plugin, plugin_instance ) ) do 
    540  
    541             -- check for data type handler 
    542             local dtype_def = plugin_def .. "." .. dtype 
    543             local stat, def = pcall( require, dtype_def ) 
    544  
    545             if stat and def and type(def.rrdargs) == "function" then 
    546  
    547                 -- temporary image matrix 
    548                 local _images = { } 
    549  
    550                 -- get diagram definitions 
    551                 for i, opts in ipairs( self:_forcelol( def.rrdargs( self, plugin, plugin_instance, dtype ) ) ) do 
    552  
    553                     _images[i] = { } 
    554  
    555                     -- get diagram definition instances 
    556                     local diagrams = self:_generic( opts, plugin, plugin_instance, dtype, i ) 
    557  
    558                     -- render all diagrams 
    559                     for j, def in ipairs( diagrams ) do 
    560  
    561                         -- remember image 
    562                         _images[i][j] = def[1] 
    563  
    564                         -- exec 
    565                         self:_rrdtool( def ) 
    566                     end 
    567                 end 
    568  
    569                 -- remember images - XXX: fixme (will cause probs with asymmetric data) 
    570                 for y = 1, #_images[1] do 
    571                     for x = 1, #_images do 
    572                         table.insert( pngs, _images[x][y] ) 
    573                     end 
    574                 end 
    575             else 
    576  
    577                 -- no data type handler, fall back to builtin definition 
    578                 if type(self.defs.definitions[dtype]) == "table" then 
    579  
    580                     -- iterate over data type instances 
    581                     for i, inst in ipairs( self.tree:data_instances( plugin, plugin_instance, dtype ) ) do 
    582  
    583                         local title = self.i18n:title( plugin, plugin_instance, dtype, inst ) 
    584                         local label = self.i18n:label( plugin, plugin_instance, dtype, inst ) 
    585                         local png   = self:mkpngpath( plugin, plugin_instance, dtype, inst ) 
    586                         local rrd   = self:mkrrdpath( plugin, plugin_instance, dtype, inst ) 
    587                         local args  = { png, "-t", title, "-v", label } 
    588  
    589                         for i, o in ipairs(self.defs.definitions[dtype]) do 
    590                             -- XXX: this is a somewhat ugly hack to exclude min/max RRAs when rrasingle is on 
    591                             if not ( self.opts.rrasingle and ( o:match("_min") or o:match("_max") ) ) then 
    592                                 table.insert( args, o ) 
    593                             end 
    594                         end 
    595  
    596                         -- remember image 
    597                         table.insert( pngs, png ) 
    598  
    599                         -- exec 
    600                         self:_rrdtool( args, rrd ) 
    601                     end 
    602                 end 
    603             end 
    604         end 
    605539    end 
    606540