Class: Fluent::Output::AmplifierFilterOutput

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

Instance Method Summary collapse

Instance Method Details

#amp_with_floor(value) ⇒ Object



56
57
58
# 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) ⇒ Object



52
53
54
# File 'lib/fluent/plugin/out_amplifier_filter.rb', line 52

def amp_without_floor(value)
  value.to_f * @ratio
end

#configure(conf) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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) ⇒ Object



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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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