Class: FFluentdLine

Inherits:
Object
  • Object
show all
Defined in:
lib/rforward/ffluentd_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFFluentdLine

Returns a new instance of FFluentdLine.



6
7
8
# File 'lib/rforward/ffluentd_line.rb', line 6

def initialize
  @client = Config.resolve Config::FLUENTD
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/rforward/ffluentd_line.rb', line 4

def client
  @client
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/rforward/ffluentd_line.rb', line 4

def host
  @host
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/rforward/ffluentd_line.rb', line 4

def port
  @port
end

#tagObject

Returns the value of attribute tag.



4
5
6
# File 'lib/rforward/ffluentd_line.rb', line 4

def tag
  @tag
end

Instance Method Details

#call(line) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rforward/ffluentd_line.rb', line 10

def call line
  Stat.instance.total += 1
  json = JSON.parse line
  json = mutate json
  @client.post Config.instance[:tag], json
  Stat.instance.success += 1
  Stat.instance.flush_counter += 1
  true
rescue Exception => e
  Stat.instance.failed += 1
  RLogger.instance.error "(#{e.message}) (line: #{line})"
  false
end

#mutate(record) ⇒ Object



24
25
26
27
28
29
# File 'lib/rforward/ffluentd_line.rb', line 24

def mutate record
  return record unless record[Config.instance['time_key']]
  time = Time.strptime record[Config.instance['time_key']], Config.instance['time_format']
  record[Config.instance['index_key']] = "fluentd-#{time.strftime('%Y-%m')}"
  record
end