class Riemann::Babbler::Sender

Constants

CHECK_CLIENT_ALIVE
HOSTNAME_FILE

Public Class Methods

new() click to toggle source
# File lib/riemann/babbler/sender.rb, line 15
def initialize
  @hostname = hostname
  @riemanns = create_riemanns
  start
end

Public Instance Methods

<<(event) click to toggle source
# File lib/riemann/babbler/sender.rb, line 21
def <<(event)
  set_event_hostname(event)
  set_event_tags(event)
  @riemanns.each {|r| r << event }
end

Private Instance Methods

create_riemanns() click to toggle source
# File lib/riemann/babbler/sender.rb, line 48
def create_riemanns
  riemanns = Array.new
  opts.riemann.host = [opts.riemann.host] if opts.riemann.host.class == String
  opts.riemann.host.each { |host| riemanns << Riemann::Babbler::Sender::Client.new(host) }
  riemanns
end
hostname() click to toggle source
# File lib/riemann/babbler/sender.rb, line 65
def hostname
  if opts.riemann.fqdn
    hostname = Socket.gethostbyname(Socket.gethostname).first
    log :debug, "Get hostname from Socket.gethostname: #{hostname}"
  else
    hostname = File.read(HOSTNAME_FILE).strip.downcase if File.exist? HOSTNAME_FILE
    log :debug, "Get hostname from #{HOSTNAME_FILE}: #{hostname}"
  end
  hostname
end
set_event_hostname(event) click to toggle source
# File lib/riemann/babbler/sender.rb, line 61
def set_event_hostname(event)
  event[:host] = @hostname unless event[:host]
end
set_event_tags(event) click to toggle source
# File lib/riemann/babbler/sender.rb, line 55
def set_event_tags(event)
  unless opts.riemann.tags.nil?
    event[:tags] = opts.riemann.tags unless event[:tags]
  end
end
start() click to toggle source
# File lib/riemann/babbler/sender.rb, line 29
def start
  Thread.new {
    loop do
      begin
        @riemanns.each do |r|
          next if r.alive?
          log :error, "Riemann client #{r.host}:#{r.port} is died, up it"
          r.start
        end
        log :debug, "Check alive of riemann client [#{@riemanns.count}]"
        sleep CHECK_CLIENT_ALIVE
      rescue
        log :error, "Riemann client sender problem"
        exit Errors::CONNECTION_PROBLEM
      end
    end
  }
end