Class: Fluent::MatchCounter
- Inherits:
-
Plugin::Filter
- Object
- Plugin::Filter
- Fluent::MatchCounter
- Defined in:
- lib/fluent/plugin/match_counter.rb
Instance Method Summary collapse
Instance Method Details
#configure(conf) ⇒ Object
31 32 33 |
# File 'lib/fluent/plugin/match_counter.rb', line 31 def configure(conf) super end |
#filter(tag, time, record) ⇒ Object
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 66 67 |
# File 'lib/fluent/plugin/match_counter.rb', line 35 def filter(tag, time, record) out = [] @match_counter.each do |mc| str = \ begin ek = mc[:event_key].to_sym next unless ek.nil? || record.has_key?(ek) record[ek] rescue record.to_s end if !!((mc[:regexp] && Regexp.new(mc[:matcher]).match(str)) || \ str.include?(mc[:matcher])) name = mc[:name].clone name.gsub!('${tag}', tag) if name.include?('${tag}') met = { name: name, value: 1 } met[:type] = mc[:type] unless mc[:type].nil? met.merge!(mc[:fields]) unless mc[:fields].nil? out << met end end return nil if out.empty? out end |
#filter_stream(tag, es) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fluent/plugin/match_counter.rb', line 69 def filter_stream(tag, es) new_es = Fluent::MultiEventStream.new es.each do |time, record| begin new_es.add(time, filter(tag, time, record)) rescue => e router.emit_error_event(tag, time, record, e) end end new_es end |