Class: SqsPoller::Metrics::SqsStatsReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/sqspoller/metrics/queue_stats_reporter.rb

Constant Summary collapse

DEFAULT_REPORTING_DELAY =

Default reporting delay is 60 seconds

60

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SqsStatsReporter

Returns a new instance of SqsStatsReporter.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sqspoller/metrics/queue_stats_reporter.rb', line 14

def initialize(options = {})
  @running = true
  @logger = SqsPoller::Logger.get_new_logger(self.class.name)

  if options[:queue_controller] == nil
    raise "Need an agent to report data from"
  end

  delay = options[:delay] || DEFAULT_REPORTING_DELAY
  queue_controller = options[:queue_controller]

  Thread.new {
    while @running
      sleep delay
      next if queue_controller.pollers.size == 0
      queue_controller.pollers.each do |queue_name, pollers|
        pollers.each.with_index(1) do |poller, index|
          stats = poller.get_poller_stats
          next if stats == nil
          @logger.info("Queue: #{queue_name}, Worker: #{index} started: #{stats.polling_started_at}, requests: #{stats.request_count}, messages: #{stats.received_message_count}, last-timestamp: #{stats.last_message_received_at}")
        end
      end
    end
  }
end

Instance Method Details

#stopObject



10
11
12
# File 'lib/sqspoller/metrics/queue_stats_reporter.rb', line 10

def stop
  @running = false
end