Class: Fluent::CouchOutput

Inherits:
BufferedOutput
  • Object
show all
Includes:
SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_couch.rb

Instance Method Summary collapse

Constructor Details

#initializeCouchOutput

Returns a new instance of CouchOutput.



53
54
55
56
# File 'lib/fluent/plugin/out_couch.rb', line 53

def initialize
    super
    require 'msgpack'
end

Instance Method Details

#configure(conf) ⇒ Object



58
59
60
# File 'lib/fluent/plugin/out_couch.rb', line 58

def configure(conf)
    super
end

#format(tag, time, record) ⇒ Object



72
73
74
# File 'lib/fluent/plugin/out_couch.rb', line 72

def format(tag, time, record)
    record.to_msgpack
end

#shutdownObject



68
69
70
# File 'lib/fluent/plugin/out_couch.rb', line 68

def shutdown
    super
end

#startObject



62
63
64
65
66
# File 'lib/fluent/plugin/out_couch.rb', line 62

def start
    super
    @couch = Couch::Server.new(@host, @port)
    @couch.put(@database, "")
end

#write(chunk) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fluent/plugin/out_couch.rb', line 76

def write(chunk)
    records = []
    chunk.open { |io|
        begin
            MessagePack::Unpacker.new(io).each { |record| records << record }
        rescue EOFError
            # EOFError always occured when reached end of chunk.
        end
    }
    #TODO: bulk insert
    for record in records
        @couch.post(@database,record.to_json)
    end
end