Class: Fluent::Plugin::PingMessageCheckerOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::PingMessageCheckerOutput
- Defined in:
- lib/fluent/plugin/out_ping_message_checker.rb
Instance Method Summary collapse
- #check_and_flush ⇒ Object
- #configure(conf) ⇒ Object
- #multi_workers_ready? ⇒ Boolean
- #process(tag, es) ⇒ Object
- #start ⇒ Object
- #update_state(list) ⇒ Object
Instance Method Details
#check_and_flush ⇒ Object
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 |
# File 'lib/fluent/plugin/out_ping_message_checker.rb', line 65 def check_and_flush notifications = [] @mutex.synchronize do @checks.keys.each do |key| if @checks[key] == 0 @checks[key] = -1 elsif @checks[key] < 0 notifications.push(key) @checks[key] = 1 else # @checks[key] > 0 if @checks[key] < @notification_times notifications.push(key) @checks[key] += 1 else @checks.delete(key) end end end end if @notifications notifications.each do |data| router.emit(@tag, Fluent::Engine.now, {@data_field => data}) end end notifications end |
#configure(conf) ⇒ Object
16 17 18 19 |
# File 'lib/fluent/plugin/out_ping_message_checker.rb', line 16 def configure(conf) super @exclude_regex = @exclude_pattern ? Regexp.compile(@exclude_pattern) : nil end |
#multi_workers_ready? ⇒ Boolean
21 22 23 |
# File 'lib/fluent/plugin/out_ping_message_checker.rb', line 21 def multi_workers_ready? true end |
#process(tag, es) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fluent/plugin/out_ping_message_checker.rb', line 43 def process(tag, es) datalist = [] es.each do |time,record| datalist.push record[@data_field] if @exclude_regex.nil? or not @exclude_regex.match(record[@data_field]) end datalist.uniq! update_state(datalist) rescue => e log.warn "unexpected error while processing events", error: e log.warn_backtrace end |
#start ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fluent/plugin/out_ping_message_checker.rb', line 25 def start super @checks = {} # 'data' => notification_counts # -1: checked in previous term, but not in this term # 0: checked in this term # 1,2,...: counts of ping missing notifications @mutex = Mutex.new timer_execute(:out_ping_messager_chacker_timer, @check_interval) do begin check_and_flush rescue => e log.warn "unexpected error", error: e log.warn_backtrace end end end |
#update_state(list) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/fluent/plugin/out_ping_message_checker.rb', line 55 def update_state(list) @mutex.synchronize do list.each do |data| if not @checks.has_key?(data) or @checks[data] != 0 @checks[data] = 0 end end end end |