class Fluent::Plugin::GelfInput
Constants
- DEFAULT_PARSER
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_gelf.rb, line 19 def initialize super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_gelf.rb, line 38 def configure(conf) compat_parameters_convert(conf, :parser) super @parser = parser_create end
emit(time, record)
click to toggle source
# File lib/fluent/plugin/in_gelf.rb, line 98 def emit(time, record) router.emit(@tag, time, record) rescue => e log.error 'gelf failed to emit', error: e.to_s, error_class: e.class.to_s, tag: @tag, record: Yajl.dump(record) end
listen()
click to toggle source
# File lib/fluent/plugin/in_gelf.rb, line 85 def listen log.info "listening gelf socket on #{@bind}:#{@port} with #{@protocol_type}" if @protocol_type == :tcp server_create(:in_tcp_server, @port, bind: @bind) do |data, conn| receive_data(data, conn) end else server_create(:in_udp_server, @port, proto: :udp, bind: @bind, max_bytes: 8192) do |data, sock| receive_data(data, sock) end end end
receive_data(data, addr)
click to toggle source
# File lib/fluent/plugin/in_gelf.rb, line 55 def receive_data(data, addr) begin msg = Gelfd2::Parser.parse(data) rescue => e log.warn 'Gelfd failed to parse a message', error: e.to_s log.warn_backtrace end # Gelfd parser will return nil if it received and parsed a non-final chunk return if msg.nil? @parser.parse(msg) { |time, record| unless time && record log.warn "pattern not match: #{msg.inspect}" return end # Use the recorded event time if available time = record.delete('timestamp').to_f if record.key?('timestamp') # Postprocess recorded event strip_leading_underscore_(record) if @strip_leading_underscore emit(time, record) } rescue => e log.error data.dump, error: e.to_s log.error_backtrace end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_gelf.rb, line 51 def shutdown super end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_gelf.rb, line 45 def start super listen end
Private Instance Methods
strip_leading_underscore_(record)
click to toggle source
# File lib/fluent/plugin/in_gelf.rb, line 106 def strip_leading_underscore_(record) record.keys.each { |k| next unless k[0,1] == '_' record[k[1..-1]] = record.delete(k) } end