class Malevich::Responder::Riemann

Constants

INTERVAL_FLUSH

Attributes

name[R]

Public Class Methods

new() click to toggle source
# File lib/malevich/responders/riemann.rb, line 14
def initialize
  @riemanns = Array.new
  @name = 'riemann client'
end

Public Instance Methods

run!() click to toggle source
# File lib/malevich/responders/riemann.rb, line 19
def run!
  make_clients
  loop do
    flush
    sleep INTERVAL_FLUSH
  end
end

Private Instance Methods

flush() click to toggle source
# File lib/malevich/responders/riemann.rb, line 47
def flush
  until malevich.riemann_events.empty?
    event = malevich.riemann_events.pop
    @riemanns.each do |riemann|
      Timeout::timeout(10) {
        log :debug, "Sent message #{event} for #{riemann.host}:#{riemann.port}"
        riemann << event
      }
    end
  end 
end
make_clients() click to toggle source
# File lib/malevich/responders/riemann.rb, line 29
def make_clients
  @riemanns.clear
  malevich.cmd[:'riemann-host'].each do |host|
    riemann, port = host.split(':')
    port ||= 5555
    client = ::Riemann::Client.new({
                                       :host => Resolv.new.getaddress(riemann),
                                       :port => port,
                                       :timeout => 10
                                   })
    client = client.tcp if malevich.cmd['riemann-tcp']
    log :debug, "Add new riemann client: #{client.host}:#{client.port}"
    @riemanns << client
    @name = @riemanns.map { |c| "riemann client [#{c.host}:#{c.port}]" }.join(' , ')
  end
  @riemanns
end