Module: SqsPoller::Metrics

Defined in:
lib/sqspoller/metrics/log_reporter.rb,
lib/sqspoller/metrics/sqs_poller_metrics.rb,
lib/sqspoller/metrics/queue_stats_reporter.rb

Defined Under Namespace

Classes: LogReporter, SqsStatsReporter

Constant Summary collapse

UNKNOWN_MESSAGE_TYPE =
"UNKNOWN"
TASK_SUCCESS_STATUS =
"success"
TASK_FAILURE_STATUS =
"failed"
NEW_RELIC_CUSTOM_METRICS_PATH =
"Custom/sqspoller/"

Class Method Summary collapse

Class Method Details

.disable_new_relic_metricsObject



70
71
72
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 70

def self.disable_new_relic_metrics
  @new_relic_metrics_enabled = false
end

.enable_new_relic_metricsObject



66
67
68
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 66

def self.enable_new_relic_metrics
  @new_relic_metrics_enabled = true
end

.get_message_status(task_status) ⇒ Object



32
33
34
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 32

def self.get_message_status(task_status)
  task_status ? TASK_SUCCESS_STATUS : TASK_FAILURE_STATUS
end

.get_message_type(task) ⇒ Object

Parameters:

  • task (Object)


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 19

def self.get_message_type(task)
  message_type = UNKNOWN_MESSAGE_TYPE
  begin
    parsed_message = JSON.parse(task[:message].body, symbolize_names: true)
    if parsed_message[:MessageType] != nil
      message_type = parsed_message[:MessageType]
    end
  rescue Exception => e
    # Ignoring When message Unknown. This happens when json is not parsable or message does not contains MessageType.
  end
  return message_type
end

.get_metrics_recorderObject



40
41
42
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 40

def self.get_metrics_recorder
  return @agent
end

.get_qpsObject



44
45
46
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 44

def self.get_qps
  return @agent.timer(:total_messages)
end

.get_queue_name(task) ⇒ Object



36
37
38
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 36

def self.get_queue_name(task)
  return task[:queue_name]
end

.get_queue_wait_time(task, timer) ⇒ Object



48
49
50
51
52
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 48

def self.get_queue_wait_time(task, timer)
  queue_time = task[:queue_time]
  start_time = timer.start_time
  return queue_time - start_time
end

.record(task, task_status, timer, elapsed_time) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sqspoller/metrics/sqs_poller_metrics.rb', line 54

def self.record(task, task_status, timer, elapsed_time)
  return if @agent.nil?
  queue_name = get_queue_name(task)
  message_type = get_message_type(task)
  message_status = get_message_status(task_status)
  queue_wait_time = get_queue_wait_time(task, timer)
  local_metrics(elapsed_time, message_status, message_type, queue_name, queue_wait_time)

  new_relic_metrics(elapsed_time, message_status, message_type, queue_name, queue_wait_time) if @new_relic_metrics_enabled

end