class Fluent::EventLastValueOutput
Attributes
last_values[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_eventlastvalue.rb, line 3 def initialize super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_eventlastvalue.rb, line 14 def configure(conf) super end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_eventlastvalue.rb, line 22 def format(tag, time, record) return '' unless @last_value_key.nil? || record[@last_value_key] [record[@id_key], record, (record[@comparator_key] || 0).to_f].to_json + "\n" end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_eventlastvalue.rb, line 18 def start super end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_eventlastvalue.rb, line 27 def write(chunk) last_values = Hash.new {|hash, key| hash[key] = Hash.new {|h,k| h[k] = nil } } last_times = Hash.new {|hash, key| hash[key] = 0} chunk.open do |io| items = io.read.split("\n") items.each do |item| key, event, t = JSON.parse(item) if @comparator_key.nil? || last_times[key] < t last_times[key] = t last_values[key] = event end end end last_values.each do |key, last_record| Fluent::Engine.emit(@emit_to, Time.now.to_i, last_record) end end