Class: Fluent::CouchOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::CouchOutput
- Includes:
- SetTagKeyMixin, SetTimeKeyMixin
- Defined in:
- lib/fluent/plugin/out_couch.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ CouchOutput
constructor
A new instance of CouchOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #update_view_index ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ CouchOutput
Returns a new instance of CouchOutput.
22 23 24 25 26 27 28 29 |
# File 'lib/fluent/plugin/out_couch.rb', line 22 def initialize super require 'msgpack' Encoding.default_internal = 'UTF-8' require 'couchrest' Encoding.default_internal = 'ASCII-8BIT' end |
Instance Method Details
#configure(conf) ⇒ Object
31 32 33 |
# File 'lib/fluent/plugin/out_couch.rb', line 31 def configure(conf) super end |
#format(tag, time, record) ⇒ Object
58 59 60 |
# File 'lib/fluent/plugin/out_couch.rb', line 58 def format(tag, time, record) record.to_msgpack end |
#shutdown ⇒ Object
54 55 56 |
# File 'lib/fluent/plugin/out_couch.rb', line 54 def shutdown super end |
#start ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fluent/plugin/out_couch.rb', line 35 def start super if @user && @password @db = CouchRest.database!("#{@protocol}://#{@user}:#{@password}@#{@host}:#{@port}/#{@database}") else @db = CouchRest.database!("#{@protocol}://#{@host}:#{@port}/#{@database}") end @views = [] if @refresh_view_index begin @db.get("_design/#{@refresh_view_index}")['views'].each do |view_name,func| @views.push([@refresh_view_index,view_name]) end rescue puts 'design document not found!' end end end |
#update_view_index ⇒ Object
69 70 71 72 73 |
# File 'lib/fluent/plugin/out_couch.rb', line 69 def update_view_index() @views.each do |design,view| @db.view("#{design}/#{view}",{"limit"=>"0"}) end end |
#write(chunk) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/fluent/plugin/out_couch.rb', line 62 def write(chunk) records = [] chunk.msgpack_each {|record| records << record } @db.bulk_save(records) update_view_index() end |