module Resque::Plugins::CloudwatchMonitor

Constants

VERSION

Public Instance Methods

dimensions(*args) click to toggle source

Array of dimensions for Cloudwatch

# File lib/resque/plugins/cloudwatch-monitor.rb, line 20
def dimensions(*args)
  []
end
get_namespace(type) click to toggle source
# File lib/resque/plugins/cloudwatch-monitor.rb, line 6
def get_namespace(type)
  Configuration.get_namespace_for(type)
end
metric_name() click to toggle source

Cloudwatch metric name

# File lib/resque/plugins/cloudwatch-monitor.rb, line 15
def metric_name
  @queue || queue
end
should_report?(type) click to toggle source
# File lib/resque/plugins/cloudwatch-monitor.rb, line 10
def should_report?(type)
  Configuration.should_report?(type)
end
timestamp() click to toggle source

Metric timestamp

# File lib/resque/plugins/cloudwatch-monitor.rb, line 25
def timestamp
  Time.now.iso8601
end
unit() click to toggle source

Cloudwatch metric unit type

# File lib/resque/plugins/cloudwatch-monitor.rb, line 30
def unit
  'Count'
end
value() click to toggle source

Cloudwatch metric value

# File lib/resque/plugins/cloudwatch-monitor.rb, line 35
def value
  1
end

Private Instance Methods

report(type, *args) click to toggle source
# File lib/resque/plugins/cloudwatch-monitor.rb, line 46
def report(type, *args)
  return unless should_report?(type)
  report_dimensions = dimensions(*args)
  report_dimensions ||= []
  report_dimensions.delete_if{|key| key[:value].nil? || key[:name].nil? }
  metric_data = {
      metric_name: metric_name.to_s,
      dimensions: report_dimensions,
      timestamp: timestamp,
      value: value,
      unit: unit.to_s
  }
  report_namespace = get_namespace(type)
  #Send to metrics. One general of the queue and another one with dimensions if custom dimensions
  metrics_to_send = report_dimensions.empty? ? [metric_data] : [metric_data, metric_data.merge(dimensions: [])]

  Configuration.cloudwatch_client.put_metric_data(namespace: report_namespace, metric_data: metrics_to_send)
end