#! /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 SpoolGrapher < Grapher def subtitle(id) case id when :spool_art "Spool (articles/s)" when :spool_byt "Spool (bytes/s)" when :spool_part "Spool (% articles)" when :spool_pbyt "Spool (% bytes)" end end def iterate false end def index(file) yield('spool', "Hiérarchies") end def register(link) if(link == 'spool') then yield(:spool_art) yield(:spool_part) yield(:spool_byt) yield(:spool_pbyt) end end def graph(link, id, gfx, file) lg = { 'fr' => [ 'fr', 'fr.*', :green ], 'news' => [ 'news', 'news.*', :blue ], 'comp' => [ 'comp', 'comp.*', :red ], '_oth' => [ 'autres', 'autres', :yellow ] } oh = [ 'fr', 'news', 'comp' , '_oth' ] of = [] Dir.glob($conf[:rrdspath] + '/*_spool.rrd') do |n| ds = File.basename(n)[0..-11] of.push(ds) unless(ds == 'me' || oh.include?(ds)) end if(id.to_s =~ /_art$/) then td = "count" else td = "size" end case id when :spool_byt, :spool_art of.each do |k| gfx.adddef(k, "#{k}_spool", td, :AVERAGE, nil, nil) end gfx.addcdef('_oth', rpn_sum(of), lg['_oth'][1]) oh.each do |k| gfx.adddef(k, "#{k}_spool", td, :AVERAGE, lg[k][1]) unless(k == '_oth') gfx.addgraph(:AREA, k, lg[k][2], lg[k][1], (k != 'fr')) end when :spool_pbyt, :spool_part gfx.lowerbound = 0 gfx.upperbound = 100 gfx.strict = true (of | oh).each do |k| gfx.adddef(k, "#{k}_spool", td, :AVERAGE, nil, nil) unless(k == '_oth') end gfx.addcdef('_oth', rpn_sum(of), nil, nil) gfx.addcdef('ttot', rpn_sum(oh) + ',100,/', nil, nil) oh.each do |k| gfx.addcdef("p#{k}", "#{k},ttot,/", lg[k][1]) gfx.addgraph(:AREA, "p#{k}", lg[k][2], lg[k][1], (k != 'fr')) end end end end