* luci/statistics: implement flip, overlay and total options for diagram models, improved/fixed netlink and wireless models

This commit is contained in:
Jo-Philipp Wich 2008-05-27 20:32:04 +00:00
parent 6a0da42bef
commit 3f09d369d6
3 changed files with 260 additions and 99 deletions

View file

@ -105,64 +105,122 @@ end
function Graph._generic( self, opts ) function Graph._generic( self, opts )
local images = { } local images = { }
local rrasingle = false -- XXX: fixme
-- remember images -- internal state variables
table.insert( images, opts.image ) local _stack_neg = { }
local _stack_pos = { }
local _longest_name = 0
local _has_totals = false
-- insert provided addition rrd options -- some convenient aliases
self:_push( { "-t", opts.title or "Unknown title" } ) local _ti = table.insert
self:_push( opts.rrd ) local _sf = string.format
-- construct an array of safe instance names -- local helper: create definitions for min, max, avg and create *_nnl (not null) variable from avg
local inst_names = { } function __def(source)
for i, source in ipairs(opts.sources) do
inst_names[i] = i .. source.name:gsub("[^A-Za-z0-9%-_]","_") local inst = source.sname
local rrd = source.rrd
local ds = source.ds
if not ds or ds:len() == 0 then ds = "value" end
local rv = { _sf( "DEF:%s_avg=%s:%s:AVERAGE", inst, rrd, ds ) }
if not rrasingle then
_ti( rv, _sf( "DEF:%s_min=%s:%s:MIN", inst, rrd, ds ) )
_ti( rv, _sf( "DEF:%s_max=%s:%s:MAX", inst, rrd, ds ) )
end end
-- create DEF statements for each instance, find longest instance name _ti( rv, _sf( "CDEF:%s_nnl=%s_avg,UN,0,%s_avg,IF", inst, inst, inst ) )
local longest_name = 0
for i, source in ipairs(opts.sources) do return rv
if source.name:len() > longest_name then
longest_name = source.name:len()
end end
local ds = source.ds or "value" -- local helper: create cdefs depending on source options like flip and overlay
function __cdef(source)
self:_push( "DEF:" .. inst_names[i] .. "_min=" ..source.rrd .. ":" .. ds .. ":MIN" ) local rv = { }
self:_push( "DEF:" .. inst_names[i] .. "_avg=" ..source.rrd .. ":" .. ds .. ":AVERAGE" ) local prev
self:_push( "DEF:" .. inst_names[i] .. "_max=" ..source.rrd .. ":" .. ds .. ":MAX" )
self:_push( "CDEF:" .. inst_names[i] .. "_nnl=" .. inst_names[i] .. "_avg,UN,0," .. inst_names[i] .. "_avg,IF" ) -- find previous source, choose stack depending on flip state
if source.flip then
prev = _stack_neg[#_stack_neg]
else
prev = _stack_pos[#_stack_pos]
end end
-- create CDEF statement for last instance name -- is first source in stack or overlay source: source_stk = source_nnl
self:_push( "CDEF:" .. inst_names[#inst_names] .. "_stk=" .. inst_names[#inst_names] .. "_nnl" ) if not prev or source.overlay then
-- create cdef statement
_ti( rv, _sf( "CDEF:%s_stk=%s_nnl", source.sname, source.sname ) )
-- create CDEF statements for each instance -- is subsequent source without overlay: source_stk = source_nnl + previous_stk
for i, source in ipairs(inst_names) do else
if i > 1 then -- create cdef statement
self:_push( _ti( rv, _sf(
"CDEF:" .. "CDEF:%s_stk=%s_nnl,%s_stk,+", source.sname, source.sname, prev
inst_names[1 + #inst_names - i] .. "_stk=" .. ) )
inst_names[1 + #inst_names - i] .. "_nnl," .. end
inst_names[2 + #inst_names - i] .. "_stk,+"
) -- create multiply by minus one cdef if flip is enabled
if source.flip then
-- create cdef statement: source_stk = source_stk * -1
_ti( rv, _sf( "CDEF:%s_neg=%s_stk,-1,*", source.sname, source.sname ) )
-- push to negative stack if overlay is disabled
if not source.overlay then
_ti( _stack_neg, source.sname )
end
-- no flipping, push to positive stack if overlay is disabled
elseif not source.overlay then
-- push to positive stack
_ti( _stack_pos, source.sname )
end
-- calculate total amount of data if requested
if source.total then
_ti( rv, _sf(
"CDEF:%s_avg_sample=%s_avg,UN,0,%s_avg,IF,sample_len,*",
source.sname, source.sname, source.sname
) )
_ti( rv, _sf(
"CDEF:%s_avg_sum=PREV,UN,0,PREV,IF,%s_avg_sample,+",
source.sname, source.sname, source.sname
) )
end
return rv
end
-- local helper: create cdefs required for calculating total values
function __cdef_totals()
if _has_totals then
return {
_sf( "CDEF:mytime=%s_avg,TIME,TIME,IF", opts.sources[1].sname ),
"CDEF:sample_len_raw=mytime,PREV(mytime),-",
"CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF"
}
else
return { }
end end
end end
-- create LINE and GPRINT statements for each instance -- local helper: create line and area statements
for i, source in ipairs(opts.sources) do function __area(source)
local legend = string.format(
"%-" .. longest_name .. "s",
source.name
)
local numfmt = opts.number_format or "%6.1lf"
local line_color local line_color
local area_color local area_color
local legend
local var
-- find color: try source, then opts.colors; fall back to random color -- find colors: try source, then opts.colors; fall back to random color
if type(source.color) == "string" then if type(source.color) == "string" then
line_color = source.color line_color = source.color
area_color = self.colors:from_string( line_color ) area_color = self.colors:from_string( line_color )
@ -177,13 +235,98 @@ function Graph._generic( self, opts )
-- derive area background color from line color -- derive area background color from line color
area_color = self.colors:to_string( self.colors:faded( area_color ) ) area_color = self.colors:to_string( self.colors:faded( area_color ) )
-- choose source_stk or source_neg variable depending on flip state
if source.flip then
var = "neg"
else
var = "stk"
end
self:_push( "AREA:" .. inst_names[i] .. "_stk#" .. area_color ) -- create legend
self:_push( "LINE1:" .. inst_names[i] .. "_stk#" .. line_color .. ":" .. legend ) legend = _sf( "%-" .. _longest_name .. "s", source.name )
self:_push( "GPRINT:" .. inst_names[i] .. "_min:MIN:" .. numfmt .. " Min" )
self:_push( "GPRINT:" .. inst_names[i] .. "_avg:AVERAGE:" .. numfmt .. " Avg" ) -- create area and line1 statement
self:_push( "GPRINT:" .. inst_names[i] .. "_max:MAX:" .. numfmt .. " Max" ) return {
self:_push( "GPRINT:" .. inst_names[i] .. "_avg:LAST:" .. numfmt .. " Last\\l" ) _sf( "AREA:%s_%s#%s", source.sname, var, area_color ),
_sf( "LINE1:%s_%s#%s:%s", source.sname, var, line_color, legend )
}
end
-- local helper: create gprint statements
function __gprint(source)
local rv = { }
local numfmt = opts.number_format or "%6.1lf"
local totfmt = opts.totals_format or "%5.1lf%s"
-- don't include MIN if rrasingle is enabled
if not rrasingle then
_ti( rv, _sf( "GPRINT:%s_min:MIN:%s Min", source.sname, numfmt ) )
end
-- always include AVERAGE
_ti( rv, _sf( "GPRINT:%s_avg:AVERAGE:%s Avg", source.sname, numfmt ) )
-- don't include MAX if rrasingle is enabled
if not rrasingle then
_ti( rv, _sf( "GPRINT:%s_max:MAX:%s Max", source.sname, numfmt ) )
end
-- include total count if requested else include LAST
if source.total then
_ti( rv, _sf( "GPRINT:%s_avg_sum:LAST:(ca. %s Total)", source.sname, totfmt ) )
else
_ti( rv, _sf( "GPRINT:%s_avg:LAST:%s Last", source.sname, numfmt ) )
end
-- end label line
rv[#rv] = rv[#rv] .. "\\l"
return rv
end
-- remember images
_ti( images, opts.image )
-- insert provided addition rrd options
self:_push( { "-t", opts.title or "Unknown title" } )
self:_push( opts.rrd )
-- store index and safe instance name within each source object,
-- find longest instance name
for i, source in ipairs(opts.sources) do
if source.name:len() > _longest_name then
_longest_name = source.name:len()
end
if source.total then
_has_totals = true
end
source.index = i
source.sname = i .. source.name:gsub("[^A-Za-z0-9%-_]","_")
end
-- create DEF statements for each instance, find longest instance name
for i, source in ipairs(opts.sources) do
self:_push( __def( source ) )
end
-- create CDEF required for calculating totals
self:_push( __cdef_totals() )
-- create CDEF statements for each instance in reversed order
for i, source in ipairs(opts.sources) do
self:_push( __cdef( opts.sources[1 + #opts.sources - i] ) )
end
-- create LINE1, AREA and GPRINT statements for each instance
for i, source in ipairs(opts.sources) do
self:_push( __area( source ) )
self:_push( __gprint( source ) )
end end
return images return images

View file

@ -6,63 +6,71 @@ function rrdargs( graph, host, plugin, plugin_instance )
-- diagram names -- diagram names
local dtypes_names = { local dtypes_names = {
"Verkehr",
"Pakete", "Pakete",
"Multicast-Pakete",
"Paketkollisionen", "Paketkollisionen",
"Paketfehler", "Paketfehler",
"Verkehr",
"RX-Fehler", "RX-Fehler",
"TX-Fehler" "TX-Fehler"
} }
-- diagram units -- diagram units
local dtypes_units = { local dtypes_units = {
"Bytes/s",
"Pakete/s",
"Pakete/s", "Pakete/s",
"Kollisionen/s", "Kollisionen/s",
"Fehler/s", -- (?) "Fehler/s", -- (?)
"Bytes/s",
"Fehler/s", "Fehler/s",
"Fehler/s" "Fehler/s"
} }
-- data source overrides -- data source overrides
local dtypes_sources = { local dtypes_sources = {
if_errors = { "rx", "tx" }, -- if_errors has rx and tx if_errors = { "tx", "rx" }, -- if_errors has tx and rx
if_octets = { "rx", "tx" } -- if_octets has rx and tx if_octets = { "tx", "rx" }, -- if_octets has tx and rx
if_packets = { "tx", "rx" }, -- if_packets has tx and rx
if_dropped = { "tx", "rx" }, -- if_dopped has tx and rx
} }
-- diagram data types -- diagram data types
local dtypes_list = { local dtypes_list = {
-- diagram 1: combined interface packet statistics -- diagram 1: interface traffic statistics
{
if_dropped = { "" }, -- packets/s
if_multicast = { "" }, -- packets/s
if_packets = { "" } -- packets/s
},
-- diagram 2: interface collision statistics
{
if_collisions = { "" } -- collisions/s
},
-- diagram 3: interface error statistics
{
if_errors = { "" } -- errors/s (?)
},
-- diagram 4: interface traffic statistics
{ {
if_octets = { "" } -- bytes/s if_octets = { "" } -- bytes/s
}, },
-- diagram 5: interface rx error statistics -- diagram 2: combined interface packet statistics
{
if_dropped = { "" }, -- packets/s
if_packets = { "" } -- packets/s
},
-- diagram 3: multicast count
{
if_multicast = { "" } -- packets/s
},
-- diagram 4: interface collision statistics
{
if_collisions = { "" } -- collisions/s
},
-- diagram 5: interface error statistics
{
if_errors = { "" } -- errors/s (?)
},
-- diagram 6: interface rx error statistics
{ {
if_rx_errors = { -- errors/s if_rx_errors = { -- errors/s
"length", "missed", "over", "crc", "fifo", "frame" "length", "missed", "over", "crc", "fifo", "frame"
} }
}, },
-- diagram 6: interface tx error statistics -- diagram 7: interface tx error statistics
{ {
if_tx_errors = { -- errors/s if_tx_errors = { -- errors/s
"aborted", "carrier", "fifo", "heartbeat", "window" "aborted", "carrier", "fifo", "heartbeat", "window"
@ -75,29 +83,35 @@ function rrdargs( graph, host, plugin, plugin_instance )
-- diagram 1 -- diagram 1
{ {
if_dropped = "ff0000", if_octets__tx_ = "00ff00",
if_multicast = "0000ff", if_octets__rx_ = "0000ff"
if_packets = "00ff00"
}, },
-- diagram 2 -- diagram 2
{ {
if_collisions = "ff0000" if_dropped__tx_ = "ff0000",
if_dropped__rx_ = "ff5500",
if_packets__tx_ = "00ff00",
if_packets__rx_ = "0000ff"
}, },
-- diagram 3 -- diagram 3
{
if_multicast = "0000ff"
},
-- diagram 4
{
if_collisions = "ff0000"
},
-- diagram 5
{ {
if_errors__tx_ = "ff0000", if_errors__tx_ = "ff0000",
if_errors__rx_ = "ff5500" if_errors__rx_ = "ff5500"
}, },
-- diagram 4 -- diagram 6
{
if_octets__tx_ = "00ff00",
if_octets__rx_ = "0000ff"
},
-- diagram 5
{ {
length = "0000ff", length = "0000ff",
missed = "ff5500", missed = "ff5500",
@ -107,7 +121,7 @@ function rrdargs( graph, host, plugin, plugin_instance )
frame = "ffff00" frame = "ffff00"
}, },
-- diagram 6 -- diagram 7
{ {
aborted = "ff0000", aborted = "ff0000",
carrier = "ffff00", carrier = "ffff00",
@ -143,14 +157,17 @@ function rrdargs( graph, host, plugin, plugin_instance )
table.insert( opts.sources, { table.insert( opts.sources, {
ds = ds, -- override ds = ds, -- override
name = name .. " (" .. ds .. ")", name = name .. " (" .. ds .. ")",
rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ) rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ),
flip = ( ds == "rx" ),
total = ( ds == "rx" or ds == "tx" )
} ) } )
end end
else else
-- no override, assume single "value" data source -- no override, assume single "value" data source
table.insert( opts.sources, { table.insert( opts.sources, {
name = name, name = name,
rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ) rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype, inst ),
total = ( name == "if_multicast" )
} ) } )
end end
end end

View file

@ -2,7 +2,7 @@ module("luci.statistics.rrdtool.definitions.wireless", package.seeall)
function rrdargs( graph, host, plugin, plugin_instance ) function rrdargs( graph, host, plugin, plugin_instance )
dtypes = { "signal_power", "signal_noise" } dtypes = { "signal_noise", "signal_power" }
opts = { } opts = { }
opts.sources = { } opts.sources = { }
@ -17,7 +17,8 @@ function rrdargs( graph, host, plugin, plugin_instance )
for i, dtype in ipairs(dtypes) do for i, dtype in ipairs(dtypes) do
opts.sources[i] = { opts.sources[i] = {
name = dtype, name = dtype,
rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype ) rrd = graph:mkrrdpath( host, plugin, plugin_instance, dtype ),
overlay = true -- don't summarize values
} }
end end