class Fluent::Output::AmplifierFilterOutput

Public Instance Methods

amp_with_floor(value) click to toggle source
# File lib/fluent/plugin/out_amplifier_filter.rb, line 56
def amp_with_floor(value)
  (value.to_f * @ratio).floor
end
amp_without_floor(value) click to toggle source
# File lib/fluent/plugin/out_amplifier_filter.rb, line 52
def amp_without_floor(value)
  value.to_f * @ratio
end
configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_amplifier_filter.rb, line 18
def configure(conf)
  super

  log.warn "'amplifier_filter' output plugin is deprecated. use 'amplifier' filter plugin instead."

  if @key_names.nil? and @key_pattern.nil?
    raise Fluent::ConfigError, "missing both of key_names and key_pattern"
  end
  if @key_names && @key_pattern
    raise Fluent::ConfigError, "cannot specify both of key_names and key_pattern"
  end
  if @key_pattern
    @key_pattern = Regexp.new(@key_pattern)
  end

  amp = if @floor
          method(:amp_with_floor)
        else
          method(:amp_without_floor)
        end
  self.define_singleton_method(:amp, amp)

  if not @remove_prefix and not @add_prefix
    raise Fluent::ConfigError, "missing both of remove_prefix and add_prefix"
  end
  if @remove_prefix
    @removed_prefix_string = @remove_prefix + '.'
    @removed_length = @removed_prefix_string.length
  end
  if @add_prefix
    @added_prefix_string = @add_prefix + '.'
  end
end
process(tag, es) click to toggle source
# File lib/fluent/plugin/out_amplifier_filter.rb, line 60
def process(tag, es)
  if @remove_prefix and
      ( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix)
    tag = tag[@removed_length..-1]
  end
  if @add_prefix
    tag = if tag and tag.length > 0
            @added_prefix_string + tag
          else
            @add_prefix
          end
  end

  pairs = []
  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
        pairs.push [time, record.merge(updated)]
      else
        pairs.push [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
        pairs.push [time, record.merge(updated)]
      else
        pairs.push [time, record.dup]
      end
    }
  end
  router.emit_array(tag, pairs)
end