Created
November 3, 2011 17:57
-
-
Save hito-asa/1337205 to your computer and use it in GitHub Desktop.
fluent-plugin-kestrel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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