X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-app-statistics%2Fluasrc%2Fstatistics%2Frrdtool.lua;h=4e00e7f1fcdf1dc4be3aece46b160b8171e31b44;hp=d8317a8177f69c041c02e3a1de40c1d98d0123dc;hb=eaafb4508c139b2aa8644c31c8349d5b25f2df8e;hpb=86ff4bd3a4a39674c51bd52576a0a87e803a7c53 diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua index d8317a817..4e00e7f1f 100644 --- a/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua +++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua @@ -25,6 +25,7 @@ function Graph.__init__( self, timespan, opts ) -- options opts.timespan = timespan or sections.rrdtool.default_timespan or 900 opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle == "1" ) + opts.rramax = opts.rramax or ( sections.collectd_rrdtool.RRAMax == "1" ) opts.host = opts.host or sections.collectd.Hostname or luci.sys.hostname() opts.width = opts.width or sections.rrdtool.image_width or 400 opts.rrdpath = opts.rrdpath or sections.collectd_rrdtool.DataDir or "/tmp/rrd" @@ -171,16 +172,29 @@ 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 + if self.opts.rrasingle or not self.opts.rramax then -- 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 ) + else + -- 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_max", source.sname, source.sname ) + end -- is subsequent source without overlay: source_stk = source_nnl + previous_stk else + if self.opts.rrasingle or not self.opts.rramax then -- 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 ) + else + -- create cdef statement + _tif( _args, "CDEF:%s_stk=%s_nnl,%s_stk,+", source.sname, source.sname, prev ) + _tif( _args, "CDEF:%s_plot=%s_max,%s_stk,+", source.sname, source.sname, prev ) + end end -- create multiply by minus one cdef if flip is enabled @@ -397,6 +411,7 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) transform_rpn = dopts.transform_rpn or "0,+", noarea = dopts.noarea or false, title = dopts.title or nil, + weight = dopts.weight or nil, ds = dsource, type = dtype, instance = dinst, @@ -469,6 +484,12 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) for i, o in ipairs(opts.rrdopts) do _ti( _args, o ) end end + -- sort sources + table.sort(_sources, function(a, b) + local x = a.weight or a.index or 0 + local y = b.weight or b.index or 0 + return x < y + end) -- create DEF statements for each instance for i, source in ipairs(_sources) do