#! /usr/local/bin/ruby require 'rubygems' # Script witten by Frederic Senault , placed # in the public domain. # No warranty at all, implied or whatever. Use at your own # risk. # To use, first, edit the code below to give the appropriate paths. # Thens, add a syslog entry like this : # # !innd,innfeed # news.notice | /path/to/innstat.rb # Then, every time the process gets a SIGUSR1, it writes perfdata # useable by ngraph. # To process the incoming feeds info, cfr the patch at : # # http://news.lacave.net/inn/status.diff # $LASTSERVICECHECK$||$HOSTNAME$||$HOSTADDRESS$||$SERVICEDESC$||$SERVICEOUTPUT$ # ||$SERVICEPERFDATA$||$SERVICECHECKCOMMAND$|| pidfile = '/var/run/news/innstat.pid' datafile = '/news/tmp/data' $ofd = ' accepted=0 refused=0 rejected=0 deferred=0 spooled=0 unspooled=0 missing=0'+ ' requeued=0 offered=0 accsize=0 rejsize=0 on_close=0 seconds=0 sleeping=0 queue=0' $ifd = ' accepted=0 refused=0 rejected=0 deferred=0 '+ ' requeued=0 offered=0 accsize=0 rejsize=0' Process.egid = 8 Process.euid = 8 Process.uid = 8 Process.gid = 8 @dl = [] File.open(pidfile, 'w') { |f| f.write(Process.pid) } def logit df = File.open(datafile + '.tmp', 'w') @dl.each do |l| df.puts l end df.close File.rename(datafile + '.tmp', datafile) @dl = [] end def export_out(moment, host, final, data) d = data.keys.sort.inject("") { |m, k| m += " #{k}=#{data[k].to_s}" } @dl.push("#{moment.to_i}||#{host}||n/a||Outgoing Feed||OK||#{host}#{d}||n/a||") if(final) then @dl.push("#{moment.to_i+1}||#{host}||n/a||Outgoing Feed||NIL||#{host}#{$fd}||n/a||") end end def export_in(moment, host, final, data) d = data.keys.sort.inject("") { |m, k| m += " #{k}=#{data[k].to_s}" } @dl.push("#{moment.to_i}||#{host}||n/a||Incoming Feed||OK||#{host}#{d}||n/a||") end Signal.trap("USR1") { logit() } Signal.trap("HUP") { logit() ; exit 0 } Signal.trap("TERM") { logit() ; exit 0 } $stdin.each do |l| if(l =~ /innfeed\[\d+\]: ([a-zA-Z0-9.-]+) (checkpoint|final) (.*)$/) then d = {} m = Time.parse(l[0,15]) h = $1 f = ($2 == 'final') t = $3 t.scan(/([a-z_]+) ([0-9.\/:,]+)/) { |k, v| d[k] = v.to_i } # to_i will blast the queue entry, and only keep the articles count # part of the deferred. export_out(m, h, f, d) elsif(l =~ /innd: ([a-zA-Z0-9.-]+) (status) (.*)$/) then d = {} m = Time.parse(l[0,15]) h = $1 f = false t = $3 t.scan(/([a-z][a-z_ ]+) ([0-9.\/:,]+)/) do |k, v| k = k[0,3] + 'size' if(k =~ / size/) d[k] = v.to_i end export_in(m, h, f, d) end end