Class: FFluentdLine
- Inherits:
-
Object
- Object
- FFluentdLine
- Defined in:
- lib/rforward/ffluentd_line.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
- #call(line) ⇒ Object
-
#initialize ⇒ FFluentdLine
constructor
A new instance of FFluentdLine.
- #mutate(record) ⇒ Object
Constructor Details
#initialize ⇒ FFluentdLine
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
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/rforward/ffluentd_line.rb', line 4 def client @client end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/rforward/ffluentd_line.rb', line 4 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/rforward/ffluentd_line.rb', line 4 def port @port end |
#tag ⇒ Object
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.}) (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 |