Class: Fluent::DeriveOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::DeriveOutput
- Defined in:
- lib/fluent/plugin/out_derive.rb
Constant Summary collapse
- KEY_MAX_NUM =
20
Instance Attribute Summary collapse
-
#key_pattern ⇒ Object
readonly
for test.
-
#key_pattern_adjustment ⇒ Object
readonly
Returns the value of attribute key_pattern_adjustment.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#prev ⇒ Object
readonly
Returns the value of attribute prev.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#get_prev_value(tag, key) ⇒ Array
Time, value.
- #save_to_prev(time, tag, key, value) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#key_pattern ⇒ Object (readonly)
for test
20 21 22 |
# File 'lib/fluent/plugin/out_derive.rb', line 20 def key_pattern @key_pattern end |
#key_pattern_adjustment ⇒ Object (readonly)
Returns the value of attribute key_pattern_adjustment.
21 22 23 |
# File 'lib/fluent/plugin/out_derive.rb', line 21 def key_pattern_adjustment @key_pattern_adjustment end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
22 23 24 |
# File 'lib/fluent/plugin/out_derive.rb', line 22 def keys @keys end |
#prev ⇒ Object (readonly)
Returns the value of attribute prev.
23 24 25 |
# File 'lib/fluent/plugin/out_derive.rb', line 23 def prev @prev end |
Instance Method Details
#configure(conf) ⇒ Object
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fluent/plugin/out_derive.rb', line 25 def configure(conf) super if @key_pattern key_pattern, @key_pattern_adjustment = @key_pattern.split(/ +/, 2) @key_pattern_adjustment = parse_adjustment(@key_pattern_adjustment) @key_pattern = Regexp.compile(key_pattern) else @keys = {} (1..KEY_MAX_NUM).each do |i| next unless conf["key#{i}"] key, adjustment = conf["key#{i}"].split(/ +/, 2) adjustment = parse_adjustment(adjustment) @keys[key] = adjustment end end raise Fluent::ConfigError, "Either of `key_pattern` or `key1` must be specified" if (@key_pattern.nil? and @keys.empty?) raise Fluent::ConfigError, "Either of `tag`, `add_tag_prefix`, or `remove_tag_prefix` must be specified" if (@tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil?) @tag_prefix = "#{@add_tag_prefix}." if @add_tag_prefix @tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix @tag_proc = if @tag Proc.new {|tag| @tag } elsif @tag_prefix and @tag_prefix_match Proc.new {|tag| "#{@tag_prefix}#{lstrip(tag, @tag_prefix_match)}" } elsif @tag_prefix_match Proc.new {|tag| lstrip(tag, @tag_prefix_match) } elsif @tag_prefix Proc.new {|tag| "#{@tag_prefix}#{tag}" } else Proc.new {|tag| tag } end raise Fluent::ConfigError, "`max` must be greater than `min`" if (@min && @max && @min >= @max) @prev = {} @mutex = Mutex.new rescue => e raise Fluent::ConfigError, "#{e.class} #{e.message} #{e.backtrace.first}" end |
#emit(tag, es, chain) ⇒ Object
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fluent/plugin/out_derive.rb', line 75 def emit(tag, es, chain) emit_tag = @tag_proc.call(tag) if @key_pattern es.each do |time, record| record.each do |key, value| next unless key =~ @key_pattern value = value.to_i prev_time, prev_value = get_prev_value(tag, key) unless prev_time && prev_value save_to_prev(time, tag, key, value) record[key] = nil next end # adjustment rate = calc_rate(tag, key, value, prev_value, time, prev_time, @key_pattern_adjustment) rate = truncate_min(rate, @min) if @min rate = truncate_max(rate, @max) if @max # Set new value record[key] = rate save_to_prev(time, tag, key, value) end Fluent::Engine.emit(emit_tag, time, record) end else #keys es.each do |time, record| @keys.each do |key, adjustment| next unless value = record[key] value = value.to_i prev_time, prev_value = get_prev_value(tag, key) unless prev_time && prev_value save_to_prev(time, tag, key, value) record[key] = nil next end # adjustment rate = calc_rate(tag, key, value, prev_value, time, prev_time, adjustment) rate = truncate_min(rate, @min) if @min rate = truncate_max(rate, @max) if @max # Set new value record[key] = rate save_to_prev(time, tag, key, value) end Fluent::Engine.emit(emit_tag, time, record) end end chain.next rescue => e log.warn e. log.warn e.backtrace.join(', ') end |
#get_prev_value(tag, key) ⇒ Array
Returns time, value.
129 130 131 |
# File 'lib/fluent/plugin/out_derive.rb', line 129 def get_prev_value(tag, key) @prev["#{tag}:#{key}"] || [] end |
#save_to_prev(time, tag, key, value) ⇒ Object
133 134 135 |
# File 'lib/fluent/plugin/out_derive.rb', line 133 def save_to_prev(time, tag, key, value) @mutex.synchronize { @prev["#{tag}:#{key}"] = [time, value] } end |
#shutdown ⇒ Object
71 72 73 |
# File 'lib/fluent/plugin/out_derive.rb', line 71 def shutdown super end |
#start ⇒ Object
67 68 69 |
# File 'lib/fluent/plugin/out_derive.rb', line 67 def start super end |