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=47e1696ece2b0ffea5a3a04eb60d5fd58067277d;hp=dbcae9dc6be42c79701c4a61662c0b6deac719f4;hb=HEAD;hpb=1bb4822dca6113f73e3bc89e2acf15935e6f8e92 diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua index dbcae9dc6..47e1696ec 100644 --- a/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua +++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua @@ -1,17 +1,5 @@ ---[[ - -Luci statistics - rrdtool interface library / diagram model interpreter -(c) 2008 Freifunk Leipzig / Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ - -]]-- +-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich +-- Licensed to the public under the Apache License 2.0. module("luci.statistics.rrdtool", package.seeall) @@ -37,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" @@ -98,7 +87,7 @@ function Graph._rrdtool( self, def, rrd ) fs.mkdirr( dir ) -- construct commandline - local cmdline = "rrdtool graph" + local cmdline = { "rrdtool", "graph" } -- copy default arguments to def stack for i, opt in ipairs(self.args) do @@ -113,15 +102,11 @@ function Graph._rrdtool( self, def, rrd ) opt = opt:gsub( "{file}", rrd ) end - if opt:match("[^%w]") then - cmdline = cmdline .. " '" .. opt .. "'" - else - cmdline = cmdline .. " " .. opt - end + cmdline[#cmdline+1] = luci.util.shellquote(opt) end -- execute rrdtool - local rrdtool = io.popen( cmdline ) + local rrdtool = io.popen(table.concat(cmdline, " ")) rrdtool:close() end @@ -183,16 +168,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 @@ -276,7 +274,7 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) -- create line1 statement _tif( _args, "LINE%d:%s_%s#%s:%s", - source.noarea and 2 or 1, + source.width or (source.noarea and 2 or 1), source.sname, var, line_color, legend ) end @@ -409,6 +407,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,12 +468,24 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index ) _ti ( _args, "-X" ) _ti ( _args, opts.units_exponent ) end + if opts.alt_autoscale then + _ti ( _args, "-A" ) + end + if opts.alt_autoscale_max then + _ti ( _args, "-M" ) + end -- store additional rrd options if opts.rrdopts then 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