Class: Fluent::Plugin::ArchagentOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::Plugin::ArchagentOutput
- Defined in:
- lib/fluent/plugin/out_archagent.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ ArchagentOutput
constructor
A new instance of ArchagentOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ ArchagentOutput
Returns a new instance of ArchagentOutput.
5 6 7 8 9 |
# File 'lib/fluent/plugin/out_archagent.rb', line 5 def initialize super require 'net/http' require 'uri' end |
Instance Method Details
#configure(conf) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fluent/plugin/out_archagent.rb', line 21 def configure(conf) super endpoint_url = 'http://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
41 42 43 |
# File 'lib/fluent/plugin/out_archagent.rb', line 41 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/fluent/plugin/out_archagent.rb', line 49 def shutdown super begin @http.finish rescue end end |
#start ⇒ Object
45 46 47 |
# File 'lib/fluent/plugin/out_archagent.rb', line 45 def start super end |
#write(chunk) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fluent/plugin/out_archagent.rb', line 57 def write(chunk) data = [] chunk.msgpack_each do |(tag, time, record)| data << 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 |