luci_statistics: Add y_min, y_max, units_exponent options and clean up some graphs
[project/luci.git] / applications / luci-statistics / luasrc / statistics / rrdtool.lua
index 844c157..dbcae9d 100644 (file)
@@ -156,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 )
@@ -180,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
@@ -253,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
@@ -400,6 +406,7 @@ 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,
@@ -450,6 +457,18 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index )
                _ti( _args, self.i18n:title( plugin, plugin_instance, _sources[1].type, instance, opts.title ) )
                _ti( _args, "-v" )
                _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