require 'sqspoller/logger/logger' # This reports the Aws::SQS::QueuePoller stats for each queue and each worker in the log. module SqsPoller module Metrics class SqsStatsReporter # Default reporting delay is 60 seconds DEFAULT_REPORTING_DELAY = 60 def stop @running = false end 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 end end end