Class: GRI::FluentWriter

Inherits:
Writer show all
Defined in:
lib/gri/plugin/writer_fluentd.rb

Constant Summary

Constants inherited from Writer

Writer::TYPES

Instance Attribute Summary

Attributes inherited from Writer

#loop

Instance Method Summary collapse

Methods inherited from Writer

create

Constructor Details

#initialize(options = {}) ⇒ FluentWriter

Returns a new instance of FluentWriter.



11
12
13
14
15
# File 'lib/gri/plugin/writer_fluentd.rb', line 11

def initialize options={}
  @options = options
  host = options[:fluent_host]
  @sock = TCPSocket.new host, 24224
end

Instance Method Details

#write(records) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/gri/plugin/writer_fluentd.rb', line 17

def write records
  time = Time.now.to_i
  for record in records
    tag = @options[:fluent_tag] || "gri.#{record['_key']}"
    s = [tag, time, record].to_msgpack
    @sock.write s
  end
end