Class: Fluent::NewrelicInsightsOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::NewrelicInsightsOutput
- Defined in:
- lib/fluent/plugin/out_newrelic_insights.rb
Instance Method Summary collapse
- #build_event(tag, time, record) ⇒ Object
- #configure(conf) ⇒ Object
- #flatten_hash(hash, prefix = '', base = hash, flattened = {}) ⇒ Object
- #format(tag, time, record) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Instance Method Details
#build_event(tag, time, record) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/fluent/plugin/out_newrelic_insights.rb', line 44 def build_event(tag, time, record) type = record[@event_type_key] return nil unless type data = @event_data_key == '.' ? record : reocrd[@event_data_key] data ||= {} return nil unless data.is_a?(Hash) data = flatten_hash(data) data.merge! "eventType" => type, "fluentTag" => tag, "timestamp" => time.to_i end |
#configure(conf) ⇒ Object
17 18 19 |
# File 'lib/fluent/plugin/out_newrelic_insights.rb', line 17 def configure(conf) super end |
#flatten_hash(hash, prefix = '', base = hash, flattened = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fluent/plugin/out_newrelic_insights.rb', line 54 def flatten_hash(hash, prefix='', base=hash, flattened={}) hash.keys.each do |k| if hash[k].is_a? Hash flatten_hash(hash[k], "#{prefix}#{k}.", base, flattened) else flattened["#{prefix}#{k}"] = hash[k] end end flattened end |
#format(tag, time, record) ⇒ Object
30 31 32 |
# File 'lib/fluent/plugin/out_newrelic_insights.rb', line 30 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
26 27 28 |
# File 'lib/fluent/plugin/out_newrelic_insights.rb', line 26 def shutdown super end |
#start ⇒ Object
21 22 23 24 |
# File 'lib/fluent/plugin/out_newrelic_insights.rb', line 21 def start super @client = Fluent::NewrelicInsights::Client.new(@account_id, @insert_key) end |
#write(chunk) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/fluent/plugin/out_newrelic_insights.rb', line 34 def write(chunk) events = [] chunk.msgpack_each do |tag, time, record| event = build_event(tag, time, record) next if event.nil? events << event end @client.insert_events(events) end |