Class: Fluent::NewrelicOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_cloudwatch_transform.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

This method is called before starting.



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

def configure(conf)
  super
end

#emit(tag, es, chain) ⇒ Object

This method is called when an event reaches Fluentd. ‘es’ is a Fluent::EventStream object that includes multiple events. You can use ‘es.each {|time,record| … }’ to retrieve events. ‘chain’ is an object that manages transactions. Call ‘chain.next’ at appropriate points and rollback if it raises an exception.

NOTE! This method is called by Fluentd’s main thread so you should not write slow routine here. It causes Fluentd’s performance degression.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fluent/plugin/out_cloudwatch_transform.rb', line 31

def emit(tag, es, chain)
  tag_parts = tag.split('.')
  last_tag = tag_parts[tag_parts.size-1]
  chain.next
  es.each {|time,record|

    newhash = Hash.new
    # though there is just one key-value pair in cloudwatch alert record, we use a loop to add context for it.
    record.each_pair do |singlekey, singlevalue|
        newhash["event_name"] = singlekey
        newhash["value"] = singlevalue.to_s
        newhash["raw"] ={singlekey => singlevalue}
    end
    # add more information for the cloudwatch alert
    timestamp = Engine.now # Should be receive_time_input
    newhash['receive_time_input']=timestamp.to_s
    newhash["application_name"] = last_tag
    newhash["intermediary_source"] = "cloudwatch"

    #log the transformed message and emit it
    $log.info "Tranformed message  #{newhash}"
    Fluent::Engine.emit @tag, time.to_i, newhash
  }
end

#shutdownObject

This method is called when shutting down.



20
21
22
# File 'lib/fluent/plugin/out_cloudwatch_transform.rb', line 20

def shutdown
  super
end

#startObject

This method is called when starting.



15
16
17
# File 'lib/fluent/plugin/out_cloudwatch_transform.rb', line 15

def start
  super
end