Class: Fluent::AmplifierFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::AmplifierFilter
- Defined in:
- lib/fluent/plugin/filter_amplifier_filter.rb
Instance Method Summary collapse
- #amp_with_floor(value) ⇒ Object
- #amp_without_floor(value) ⇒ Object
- #configure(conf) ⇒ Object
- #filter_stream(tag, es) ⇒ Object
Instance Method Details
#amp_with_floor(value) ⇒ Object
46 47 48 |
# File 'lib/fluent/plugin/filter_amplifier_filter.rb', line 46 def amp_with_floor(value) (value.to_f * @ratio).floor end |
#amp_without_floor(value) ⇒ Object
42 43 44 |
# File 'lib/fluent/plugin/filter_amplifier_filter.rb', line 42 def amp_without_floor(value) value.to_f * @ratio end |
#configure(conf) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fluent/plugin/filter_amplifier_filter.rb', line 16 def configure(conf) super if @key_names.nil? and @key_pattern.nil? raise Fluent::ConfigError, "missing both of key_names and key_pattern" end if not @key_names.nil? and not @key_pattern.nil? raise Fluent::ConfigError, "cannot specify both of key_names and key_pattern" end if @key_names @key_names = @key_names.split(',') end if @key_pattern @key_pattern = Regexp.new(@key_pattern) end amp = if @floor method(:amp_with_floor) else method(:amp_without_floor) end (class << self; self; end).module_eval do define_method(:amp, amp) end end |
#filter_stream(tag, es) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fluent/plugin/filter_amplifier_filter.rb', line 50 def filter_stream(tag, es) new_es = Fluent::MultiEventStream.new if @key_names es.each {|time,record| updated = {} @key_names.each {|key| val = record[key] next unless val updated[key] = amp(val) } log.debug "amplifier tag:#{tag} floor:#{@floor} ratio:#{@ratio} updated:#{updated.to_json} record:#{record.to_json}" if updated.size > 0 new_es.add(time, record.merge(updated)) else new_es.add(time, record.dup) end } else @key_pattern es.each {|time,record| updated = {} record.keys.each {|key| val = record[key] next unless val next unless @key_pattern.match(key) updated[key] = amp(val) } log.debug "amplifier tag:#{tag} floor:#{@floor} ratio:#{@ratio} updated:#{updated.to_json} record:#{record.to_json}" if updated.size > 0 new_es.add(time, record.merge(updated)) else new_es.add(time, record.dup) end } end new_es end |