Module: Fluent::EventSnifferPlugin::EngineUtil
- Defined in:
- lib/fluent/plugin/eventsniffer/engine_util.rb
Class Method Summary collapse
Class Method Details
.get_sniffed_results ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/fluent/plugin/eventsniffer/engine_util.rb', line 47 def self.get_sniffed_results Engine.instance_eval do res = @sniff_buf @sniff_buf = [] res end end |
.restore ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fluent/plugin/eventsniffer/engine_util.rb', line 35 def self.restore $log.info "restore original Engine" Engine.instance_eval do alias :emit_stream :original_emit_staream undef :original_emit_staream @sniff_match_pattern = nil @sniff_match_cache = nil @sniff_buf = nil @sniff_max_events = nil end end |
.sniff(pattern, max_events) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fluent/plugin/eventsniffer/engine_util.rb', line 4 def self.sniff(pattern, max_events) $log.info "start to sniff with pattern '#{pattern}'" Engine.instance_eval do alias :original_emit_staream :emit_stream @sniff_match_pattern = Fluent::MatchPattern.create(pattern) @sniff_match_cache = {} @sniff_buf = [] @sniff_max_events = max_events def emit_stream(tag, es) if @sniff_buf.size < @sniff_max_events matched = @sniff_match_cache[tag] if matched.nil? matched = @sniff_match_pattern.match(tag) @sniff_match_cache[tag] = matched end if matched es.dup.each do |time, record| @sniff_buf.push({tag:tag, time:time, record:record}) end end end original_emit_staream(tag, es) end end end |