Module: Fluent::Plugin

Defined in:
lib/fluent/plugin/out_archagent.rb

Defined Under Namespace

Classes: ArchagentOutput

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fluent/plugin/out_archagent.rb', line 25

def configure(conf)
  super

  endpoint_url = 'localhost:' + @port
  # Check if endpoint URL is valid
  unless endpoint_url =~ /^#{URI.regexp}$/
    fail Fluent::ConfigError, 'port invalid'
  end

  begin
    @uri = URI.parse(endpoint_url)
  rescue URI::InvalidURIError
    raise Fluent::ConfigError, 'port invalid'
  end

  @http = Net::HTTP.new(@uri.host, @uri.port)
  @http.read_timeout = @http_read_timeout
  @http.open_timeout = @http_open_timeout
end

#format(tag, time, record) ⇒ Object



45
46
47
# File 'lib/fluent/plugin/out_archagent.rb', line 45

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

#initializeObject



9
10
11
12
13
# File 'lib/fluent/plugin/out_archagent.rb', line 9

def initialize
  super
  require 'net/http'
  require 'uri'
end

#shutdownObject



53
54
55
56
57
58
59
# File 'lib/fluent/plugin/out_archagent.rb', line 53

def shutdown
  super
  begin
    @http.finish
  rescue
  end
end

#startObject



49
50
51
# File 'lib/fluent/plugin/out_archagent.rb', line 49

def start
  super
end

#write(chunk) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fluent/plugin/out_archagent.rb', line 61

def write(chunk)
  data = []
  chunk.msgpack_each do |(tag, time, record)|
    data << [tag, time, record]
  end

  request = create_request(data)

  begin
    response = @http.start do |http|
      request = create_request(data)
      http.request request
    end
  rescue IOError, EOFError, SystemCallError => e
    # server didn't respond
    $log.warn "Net::HTTP.#{request.method.capitalize} raises exception: #{e.class}, '#{e.message}'"
  ensure
    begin
      @http.finish
    rescue
    end
  end
end