module Panoptimon::CollectorSink
Public Class Methods
new(handler)
click to toggle source
# File lib/panoptimon/collector.rb, line 81 def initialize (handler) @handler = handler @timeout = @handler.config[:timeout] @interval = @handler.config[:interval] timer_on end
Public Instance Methods
on_unbind(&block)
click to toggle source
# File lib/panoptimon/collector.rb, line 126 def on_unbind (&block); @on_unbind = block; end
receive_data(data)
click to toggle source
# File lib/panoptimon/collector.rb, line 104 def receive_data (data) timer_on @handler.logger.debug "incoming" @buf ||= BufferedTokenizer.new("\n") @buf.extract(data).each do |line| timer_on(with_interval: true) begin data = JSON.parse(line) rescue # TODO feed errors up to the monitor $stderr.puts "error parsing #{line.dump} - #{$!}" end @handler.logger.debug "line: #{line}" @handler.bus.notify(Metric.new(@handler.name, data)) end end
receive_stderr(mess)
click to toggle source
# File lib/panoptimon/collector.rb, line 121 def receive_stderr (mess) @handler.noise(mess) (@err_mess ||= '') << mess end
timer_off()
click to toggle source
# File lib/panoptimon/collector.rb, line 100 def timer_off @timer.cancel end
timer_on(opts={})
click to toggle source
reset / start timeout timer
# File lib/panoptimon/collector.rb, line 89 def timer_on (opts={}) @timer.cancel unless @timer.nil? length = @timeout + (opts[:with_interval] ? @interval : 0) @timer = EventMachine::Timer.new(length) { scrap = @buf ? " - #{@buf.flush}" : '' @handler.logger.error "timeout on #{@handler.name}" + scrap @handler.logger.debug {"pid #{get_pid}"} close_connection() } end
unbind()
click to toggle source
# File lib/panoptimon/collector.rb, line 127 def unbind timer_off @on_unbind.call(get_status.exitstatus, @err_mess) end