#! /usr/local/bin/ruby # Copyright (c) 2006 Frédéric Senault. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the author or any contributors may be used to # endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. class BWGrapher < Grapher def subtitle(id) case id when :bw then "Bande passante (/seconde)" when :pkts then "Paquets transmis (/seconde)" end end def index(file) if(file =~ /^(.*)_(lan|net)_bw$/) then t = $1.to_s r = ( $2.to_s == 'net' ? 'Internet' : 'LAN' ) t.gsub!(/_/, ' ') yield(file, "Bande passante #{r}, #{t}") end end def register(link) if(link =~ /_bw$/) then yield(:bw) yield(:pkts) end end def graph(link, id, gfx, file) case id when :bw then gfx.adddef('in_bytes', file, 'in_bytes', :AVERAGE, \ 'Bytes entrants', '%8.3lf%s') gfx.adddef('out_bytes', file, 'out_bytes', :AVERAGE, \ 'Bytes sortants', '%8.3lf%s') gfx.addcdef('out_bytes_i', '0,out_bytes,-', nil, nil) tg = gfx.addgraph(:AREA, 'in_bytes', nil, 'Bytes') tg = gfx.addgraph(:AREA, 'out_bytes_i', tg.color, '') gfx.addgraph(:LINE, '0', '000000', '') when :pkts then gfx.adddef('in_error', file, 'in_error', :AVERAGE, \ 'Paquets entrants en erreur', '%8.3lf') gfx.adddef('in_discd', file, 'in_discd', :AVERAGE, \ 'Paquets entrants ignorés', '%8.3lf') gfx.adddef('in_bcast', file, 'in_bcast', :AVERAGE, \ 'Paquets entrants broadcast', '%8.3lf') gfx.adddef('in_ucast', file, 'in_ucast', :AVERAGE, \ 'Paquets entrants unicast', '%8.3lf') gfx.adddef('out_error', file, 'out_error', :AVERAGE, \ 'Paquets sortants en erreur', '%8.3lf') gfx.adddef('out_discd', file, 'out_discd', :AVERAGE, \ 'Paquets sortants ignorés', '%8.3lf') gfx.adddef('out_bcast', file, 'out_bcast', :AVERAGE, \ 'Paquets sortants broadcast', '%8.3lf') gfx.adddef('out_ucast', file, 'out_ucast', :AVERAGE, \ 'Paquets sortants unicast', '%8.3lf') gfx.addcdef('out_error_i', '0,out_error,-', nil, nil) gfx.addcdef('out_discd_i', '0,out_discd,-', nil, nil) gfx.addcdef('out_bcast_i', '0,out_bcast,-', nil, nil) gfx.addcdef('out_ucast_i', '0,out_ucast,-', nil, nil) tge = gfx.addgraph(:AREA, 'in_error', nil, 'Erreur') tgd = gfx.addgraph(:AREA, 'in_discd', nil, 'Ignorés', true) tgb = gfx.addgraph(:AREA, 'in_bcast', nil, 'Broadcasts', true) tgu = gfx.addgraph(:AREA, 'in_ucast', nil, 'Unicasts', true) tgi = gfx.addgraph(:AREA, 'out_error_i', tge.color, '') tgi = gfx.addgraph(:AREA, 'out_discd_i', tgd.color, '', true) tgi = gfx.addgraph(:AREA, 'out_bcast_i', tgb.color, '', true) tgi = gfx.addgraph(:AREA, 'out_ucast_i', tgu.color, '', true) gfx.addgraph(:LINE, '0', '000000', '') end end end