Skip to content

Instantly share code, notes, and snippets.

@hito-asa
Created November 3, 2011 17:57
Show Gist options
  • Save hito-asa/1337205 to your computer and use it in GitHub Desktop.
Save hito-asa/1337205 to your computer and use it in GitHub Desktop.
fluent-plugin-kestrel
module Fluent
class KestrelOutput < BufferedOutput
Fluent::Plugin.register_output('kestrel', self)
attr_reader :hosts, :kestrel
def initialize
super
require 'msgpack'
require 'kestrel'
end
def configure(conf)
super
hosts_source = conf.has_key?('hosts') ? conf['hosts'] : 'localhost:22133'
@hosts = hosts_source.split(/\s*,\s*/)
end
def start
super
@kestrel = Kestrel::Client.new(@hosts)
end
def shutdown
end
def format(tag, time, record)
event.record.to_msgpack
end
----
def format(tag, event)
event.record.to_msgpack
end
def write(chunk)
chunk.open { |io|
begin
MessagePack::Unpacker.new(io).each.each_with_index { |record, index|
@kestrel.set(record['key'], record['value'],0)
}
rescue EOFError
# EOFError always occured when reached end of chunk.
end
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment