Class: Fluent::GrayLogOutput

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGrayLogOutput

Returns a new instance of GrayLogOutput.



12
13
14
# File 'lib/fluent/plugin/out_graylog.rb', line 12

def initialize
  super
end

Instance Attribute Details

#endpointObject (readonly)

rubocop:enable Style/NumericLiterals



10
11
12
# File 'lib/fluent/plugin/out_graylog.rb', line 10

def endpoint
  @endpoint
end

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (ConfigError)


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

def configure(conf)
  super
  raise ConfigError, "'host' parameter required" unless conf.key?('host')
end

#format(_tag, _time, record) ⇒ Object



29
30
31
32
# File 'lib/fluent/plugin/out_graylog.rb', line 29

def format(_tag, _time, record)
  # Record must already be in GELF
  record.to_msgpack
end

#shutdownObject



25
26
27
# File 'lib/fluent/plugin/out_graylog.rb', line 25

def shutdown
  super
end

#startObject



21
22
23
# File 'lib/fluent/plugin/out_graylog.rb', line 21

def start
  super
end

#write(chunk) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fluent/plugin/out_graylog.rb', line 35

def write(chunk)
  records = []
  chunk.msgpack_each do |record|
    records.push JSON.dump(record) + "\0" # Message delimited by null char
  end

  log.debug 'establishing connection with GrayLog'
  socket = TCPSocket.new @host, @port

  begin
    log.debug "sending #{records.count} records in batch"
    socket.write records.join
  ensure
    log.debug 'closing connection with GrayLog'
    socket.close
  end
end