class Fluent::RiemannOutput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_riemann.rb, line 14
def initialize
  super
end

Public Instance Methods

client() click to toggle source
# File lib/fluent/plugin/out_riemann.rb, line 41
def client
  @_client ||= Riemann::Client.new :host => @host, :port => @port, :timeout => @timeout
  @protocol == 'tcp' ? @_client.tcp : @_client.udp
end
configure(c) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_riemann.rb, line 18
def configure(c)
  super

  @_types = parse_map(@types) do |k, t|
    case t
    when "string" then "to_s"
    when "integer" then "to_i"
    when "float" then "to_f"
    else t
    end
  end

  @_fields = parse_map(@fields) { |k, f| (f || k).to_sym }
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_riemann.rb, line 46
def format(tag, time, record)
  [tag, time, record].to_msgpack
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_riemann.rb, line 37
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_riemann.rb, line 33
def start
  super
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_riemann.rb, line 50
def write(chunk)
  chunk.msgpack_each do |tag, time, record|
    event = {
      :time => time,
      :service => @service,
      :tags => tag.split('.')
    }

    @_fields.each { |k,v| event[v] = record[k] }
    @_types.each { |k,t| event[k] = event[k].send(t) }

    client << event
  end
end

Private Instance Methods

parse_map(map, &block) click to toggle source
# File lib/fluent/plugin/out_riemann.rb, line 67
def parse_map(map, &block)
  Hash[map.split(',').map do |m|
    k, v = m.split(':').map(&:strip)
    if block_given?
      [k, yield(k, v)]
    else
      [k, v]
    end
  end]
end