Sha256: f5f5340f2971b336c100a9e74c140985a73a5e9301fa7ba58545791a738a71e4

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# encoding: utf-8

require "kurchatov/riemann/client"
require "kurchatov/mixin/queue"

module Kurchatov
  module Responders
    class Riemann < Kurchatov::Plugin

      include Kurchatov::Mixin::Queue

      FLUSH_INTERVAL = 0.5

      def initialize(conn)
        @hosts = conn
        @riemanns = Array.new
      end

      def run
        make_clients
        loop { flush; sleep FLUSH_INTERVAL }
      end

      private

      def make_clients
        @riemanns.clear
        @hosts.each do |host|
          riemann, port = host.split(':')
          @riemanns << Kurchatov::Riemann::Client.new(:host => riemann, :port => port)
          @name = @riemanns.map { |c| "riemann client [#{c.host}:#{c.port}]" }.join(' , ')
        end
      end

      def flush
        @events_to_send ||= events.all
        unless @events_to_send.empty?
          @riemanns.each {|riemann| riemann << @events_to_send }
          Log.debug("Sended events via #{@name.inspect}: #{@events_to_send}")
        end
        @events_to_send = nil
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kurchatov-0.0.2 lib/kurchatov/responders/riemann.rb
kurchatov-0.0.2b lib/kurchatov/responders/riemann.rb
kurchatov-0.0.1 lib/kurchatov/responders/riemann.rb