Class: Fluent::RawTcpOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_rawtcp.rb

Defined Under Namespace

Classes: Node, RawNodeConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRawTcpOutput

Returns a new instance of RawTcpOutput.



6
7
8
9
10
11
12
# File 'lib/fluent/plugin/out_rawtcp.rb', line 6

def initialize
  super
  require 'socket'
  require 'timeout'
  require 'fileutils'
  @nodes = []  #=> [Node]
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



16
17
18
# File 'lib/fluent/plugin/out_rawtcp.rb', line 16

def nodes
  @nodes
end

Instance Method Details

#configure(conf) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fluent/plugin/out_rawtcp.rb', line 18

def configure(conf)
  super

  conf.elements.each do |e|
    next if e.name != "server"

    host = e['host']
    port = e['port']
    port = port ? port.to_i : DEFAULT_LISTEN_PORT

    name = e['name']
    unless name
      name = "#{host}:#{port}"
    end

    node_conf = RawNodeConfig.new(name, host, port)
    @nodes << Node.new(log, node_conf)
    log.info "adding forwarding server '#{name}'", :host=>host, :port=>port
  end
end

#format(tag, time, record) ⇒ Object



47
48
49
# File 'lib/fluent/plugin/out_rawtcp.rb', line 47

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

#shutdownObject



43
44
45
# File 'lib/fluent/plugin/out_rawtcp.rb', line 43

def shutdown
  super
end

#startObject



39
40
41
# File 'lib/fluent/plugin/out_rawtcp.rb', line 39

def start
  super
end

#write(chunk) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fluent/plugin/out_rawtcp.rb', line 51

def write(chunk)
  return if chunk.empty?

  error = nil

  @nodes.each do |node|
    begin
      send_data(node, chunk)
      return
    rescue
      error = $!
    end
  end

  raise error if error
  raise "No nodes available"
end