#! /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 NewsFeedGrapher < Grapher KEYS = [ 'accepted', 'accsize', 'deferred', 'missing', 'offered', 'on_close', 'queue', 'refused', 'rejected', 'rejsize', 'requeued', 'seconds', 'spooled', 'unspooled', 'sleeping' ] def subtitle(id) case id when :feed_art, :afeed_art "Feed sortant (articles/s)" when :feed_byt, :afeed_byt "Feed sortant (bytes/s)" when :feed_part, :afeed_part "Feed sortant (% articles)" when :feed_pbyt, :afeed_pbyt "Feed sortant (% bytes)" end end def index(file) if(file =~ /^(.*)_feed$/) then t = $1 t.gsub!(/_/, ' ') yield(file, "Feed sortant, #{t}") elsif(file == '.') then yield('allfeed', "Feeds sortants (total)") end end def register(link) if(link =~ /_feed$/) then yield(:feed_art) yield(:feed_part) yield(:feed_byt) yield(:feed_pbyt) elsif(link == 'allfeed') then yield(:afeed_art) yield(:afeed_part) yield(:afeed_byt) yield(:afeed_pbyt) end end def ifu(value, uvalue) "#{value},UN,#{uvalue.to_s},#{value},IF" end def gen(k, f) (0..f.length-1).collect { |i| "#{k}_#{i}" } end def graph(link, id, gfx, file) lg = { 'acc' => [ 'accepted', 'Acceptés', :green ], 'ref' => [ 'refused', 'Refusés', :yellow ], 'def' => [ 'deferred', 'Retardés', :magenta ], 'rej' => [ 'rejected', 'Rejetés', :red ], 'spo' => [ 'spooled', 'Spoolés', :darkgray ], 'uns' => [ 'unspooled', 'Déspoolés', :blue ], 'mis' => [ 'missing', 'Manquants', :lightgray ], 'req' => [ 'requeued', 'Remis en queue', :blue ] } if(id.to_s[0,1] == 'a') then all = true f = [] Dir.glob($conf[:rrdspath] + '/*_feed.rrd') do |n| f.push(File.basename(n)[0..-5]) #break if(f.length > 16) end else all = false f = [ file ] end isart = (id.to_s =~ /art$/) oa = [ 'uns', 'rej', 'acc', 'ref', 'def', 'mis', 'req', 'spo', 'nsp' ] op = [ 'uns', 'rej', 'ref', 'def', 'mis', 'req', 'acc', 'spo' ] os = [ 'rej', 'acc' ] case id when :feed_byt, :afeed_byt, :feed_art, :afeed_art (isart ? oa : os).each do |k| if(k == 'nsp') then gfx.addcdef('nsp', '0,spo,-', nil, nil) gfx.addgraph(:AREA, k, lg['spo'][2], lg['spo'][1], false) else f.each_index do |i| gfx.adddef("#{k}_#{i}", f[i], \ (isart ? lg[k][0] : "#{k}size"), \ :AVERAGE, nil, nil) end gfx.addcdef("#{k}", rpn_sum(gen(k, f)), lg[k][1]) gfx.addgraph(:AREA, k, lg[k][2], lg[k][1], true) unless(k == 'spo') end end when :feed_part, :afeed_part, :feed_pbyt, :afeed_pbyt gfx.percent = true (isart ? op : os).each do |k| f.each_index do |i| gfx.adddef("#{k}_#{i}", f[i], \ (isart ? lg[k][0] : "#{k}size"), \ :AVERAGE, nil, nil) end gfx.addcdef("#{k}", rpn_sum(gen(k, f)), nil, nil) end gfx.addcdef('ttot', rpn_sum((isart ? op : os)) + ',100,/', nil, nil) (isart ? op : os).each do |k| gfx.addcdef("p#{k}", "#{k},ttot,/", lg[k][1]) gfx.addgraph(:AREA, "p#{k}", lg[k][2], lg[k][1], true) end end end end class GlobalNewsFeedGrapher < NewsFeedGrapher def iterate false end end