Class: ResqueToCloudwatch::CloudwatchSender

Inherits:
Object
  • Object
show all
Defined in:
lib/resque_to_cloudwatch/cloudwatch_sender.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CloudwatchSender

Pass an instance of CloudwatchToResque::Config



7
8
9
# File 'lib/resque_to_cloudwatch/cloudwatch_sender.rb', line 7

def initialize(config)
  @config = config
end

Instance Method Details

#inspectObject



30
31
32
# File 'lib/resque_to_cloudwatch/cloudwatch_sender.rb', line 30

def inspect
  to_s
end

#send_value(value, metric_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/resque_to_cloudwatch/cloudwatch_sender.rb', line 11

def send_value(value, metric_name)
  @config.region.each do |region|
    dimensions = []
    dimensions << {:name => 'project', :value => @config.project}
    dimensions << {:name => 'hostname', :value => @config.hostname} unless @config.hostname.nil?
    cw = AWS::CloudWatch.new(region: region)
    cw.client.put_metric_data({
      :namespace      => "#{@config.namespace}/resque",
      :metric_data    => [
        :metric_name  => metric_name,
        :dimensions   => dimensions,
        :value => value,
        :unit  => 'Count'
      ]
    })
    $log.info "CloudwatchSender: Sent metric value #{value} for #{metric_name} to region #{region}"
  end
end

#to_sObject



34
35
36
# File 'lib/resque_to_cloudwatch/cloudwatch_sender.rb', line 34

def to_s
  "CloudwatchSender"
end