Class: Fluent::ThresholdOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::ThresholdOutput
- Includes:
- HandleTagNameMixin
- Defined in:
- lib/fluent/plugin/out_threshold.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#filter_record(tag, time, record) ⇒ Object
This method is called when an event reaches to Fluentd.
-
#initialize ⇒ ThresholdOutput
constructor
<match *> condition eq | ne | gl | ge | lt | le threshold <float> | <integer> target_key <key_name> </match>.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ ThresholdOutput
<match *>
condition eq | ne | gl | ge | lt | le
threshold <float> | <integer>
target_key <key_name>
</match>
21 22 23 |
# File 'lib/fluent/plugin/out_threshold.rb', line 21 def initialize super 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 |
# File 'lib/fluent/plugin/out_threshold.rb', line 25 def configure(conf) super @labelled = !conf['@label'].nil? if !@labelled && !@remove_tag_prefix && !@remove_tag_suffix && !@add_tag_prefix && !@add_tag_suffix raise ConfigError, "fluent-plugin-threshold: Set 'remove_tag_prefix', 'remove_tag_suffix', 'add_tag_prefix' or 'add_tag_suffix'." end # You can also refer raw parameter via conf[name]. unless @condition raise ConfigError, "fluent-plugin-threshold: 'filter' parameter is required" end unless @threshold raise ConfigError, "fluent-plugin-threshold: 'threshold' parameter is required" end unless @target_key raise ConfigError, "fluent-plugin-threshold: 'target_key' parameter is required" end end |
#emit(tag, es, chain) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fluent/plugin/out_threshold.rb', line 94 def emit(tag, es, chain) es.each do |time, record| _tag = tag.clone record = filter_record(_tag, time, record) if record.any? router.emit(_tag, time, record) end end chain.next end |
#filter_record(tag, time, record) ⇒ Object
This method is called when an event reaches to Fluentd. Convert the event to a raw string.
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 86 87 88 89 90 91 92 |
# File 'lib/fluent/plugin/out_threshold.rb', line 58 def filter_record(tag, time, record) super filter_record = {} case @condition when "eq" if record.member?(@target_key) && record[@target_key].to_f == threshold.to_f filter_record = record end when "ne" if record.member?(@target_key) && record[@target_key].to_f != threshold.to_f filter_record = record end when "ge" if record.member?(@target_key) && record[@target_key].to_f >= threshold.to_f filter_record = record end when "gt" if record.member?(@target_key) && record[@target_key].to_f > threshold.to_f filter_record = record end when "le" if record.member?(@target_key) && record[@target_key].to_f <= threshold.to_f filter_record = record end when "lt" if record.member?(@target_key) && record[@target_key].to_f < threshold.to_f filter_record = record end else raise ArgumentError.new("no such condition: #{@condition}") end filter_record end |
#shutdown ⇒ Object
52 53 54 |
# File 'lib/fluent/plugin/out_threshold.rb', line 52 def shutdown super end |
#start ⇒ Object
48 49 50 |
# File 'lib/fluent/plugin/out_threshold.rb', line 48 def start super end |