resque_to_cloudwatch 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11e5ee66485c3ad30e8ceb3c2c62918025b90433
4
- data.tar.gz: c5cdef90cef5a6ac4dc60619add241626425707d
3
+ metadata.gz: e688f02a4e8350b45d45cbb941e1730695fce9e7
4
+ data.tar.gz: 97bd4396f9274ede34bea4a61de46107379bf51a
5
5
  SHA512:
6
- metadata.gz: 0d66e4be36c5b12e0fa3084630c6bfd39accee9d5fbb983ae66aefd2536c99cea7a1199bfb1d4e621fa4490293892ba3437486b94a60c8bb57c3d350d8514e9e
7
- data.tar.gz: 956431e69c343e0dabff5e28a128b322269c602862ba764b8b6014595a48ba0f931fe7ec2021e0caee77bd021a85628e58a36794eba8df8fa61cdaed2e25fc5b
6
+ metadata.gz: 8d350622314c3713b29f232b9dab78ff3629e0ced410c15aa86eef5f7257845b3a58fa617e92d7b12ad31c160ed765b0bff9e05a611eb3c56a4574cc253f744a
7
+ data.tar.gz: 91f2c68bf7607025efd1bedd4c7cae82eaf2395cdbaabccbcdde34df48bfed5146d8b2b19358b4032be7733840c768990ef20a7166ec86de02b5fb098f8f230d
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ test_config.yaml
data/.ruby-gemset CHANGED
@@ -1 +1 @@
1
- ops-cloudwatchd
1
+ resque_to_cloudwatch
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # resque_to_cloudwatch
2
2
 
3
- This is a gem containing a daemon for submitting Resque queue lengths to AWS
4
- Cloudwatch. In addition, it can submit this metric to Graphite.
3
+ This is a gem containing a daemon for submitting Resque queue lengths and the number
4
+ of Resque workers currently working to AWS Cloudwatch. In addition, it can (optionally)
5
+ submit this metric to Graphite.
5
6
 
6
7
  ## Usage
7
8
 
@@ -32,17 +33,17 @@ Your AWS access key/secret key pair.
32
33
 
33
34
  #### `region`
34
35
 
35
- Region of Cloudwatch the metric should be submitted to.
36
+ Region of Cloudwatch the metrics should be submitted to.
36
37
 
37
38
  #### `project`, `namespace`, `hostname`
38
39
 
39
40
  These can actually contain any text - they are submitted as "dimensions" along
40
41
  with the metric value. A single metric in Cloudwatch is uniquely identified by
41
- its name (hardcoded to `jobs_queued` in this gem), and any dimensions it has.
42
- At Forward3D, we have a number of autoscaling "projects" (codebases), so we use
43
- the project dimension to represent that. Namespace is more important, as that
44
- determines how the metric is categorised in the Cloudwatch interface. Hostname
45
- can be anything - we set it to the hostname of the submitting machine.
42
+ its name (hardcoded to `jobs_queued` and `workers_working` in this gem), and any
43
+ dimensions it has. At Forward3D, we have a number of autoscaling "projects"
44
+ (codebases), so we use the project dimension to represent that. Namespace is more
45
+ important, as that determines how the metric is categorised in the Cloudwatch interface.
46
+ Hostname can be anything - we set it to the hostname of the submitting machine.
46
47
 
47
48
  #### `redis_host`, `redis_port`
48
49
 
@@ -61,4 +62,4 @@ The period of the EventMachine loop - how often stats are collected and sent.
61
62
 
62
63
  The Graphite metric name will look like this:
63
64
 
64
- resque_to_cloudwatch.namespace.hostname.project
65
+ resque_to_cloudwatch.namespace.metric_name.hostname.project
@@ -17,21 +17,28 @@ end.parse!
17
17
 
18
18
  options[:config] ||= "#{File.expand_path("../../config.yaml", __FILE__)}"
19
19
  config = ResqueToCloudwatch::Config.new(options[:config])
20
- collector = ResqueToCloudwatch::Collector.new(config)
21
20
 
22
21
  # Initialize senders we're going to use
23
22
  senders = []
24
23
  senders << ResqueToCloudwatch::CloudwatchSender.new(config)
25
24
  senders << ResqueToCloudwatch::GraphiteSender.new(config) if config.enable_graphite
26
-
27
25
  $log.info "Senders in use: #{senders.join(", ")}"
28
26
  $log.info "Entering EventMachine loop with period of #{config.period} seconds"
29
27
 
28
+ # Initialize collectors we're going to use
29
+ collectors = []
30
+ collectors << ResqueToCloudwatch::QueueLengthCollector.new(config)
31
+ collectors << ResqueToCloudwatch::WorkersWorkingCollector.new(config)
32
+ $log.info "Collectors in use: #{collectors.join(", ")}"
33
+
34
+
30
35
  EventMachine.run do
31
36
  EventMachine.add_periodic_timer(config.period) do
32
37
  senders.each do |sender|
33
38
  begin
34
- sender.send_value(collector.get_queue_length)
39
+ collectors.each do |collector|
40
+ sender.send_value(collector.get_value, collector.metric_name)
41
+ end
35
42
  rescue => e
36
43
  $log.error "Exception sending or collecting data with sender #{sender}: #{e.message}"
37
44
  e.backtrace.each do |line|
@@ -5,4 +5,4 @@ $log = Logger.new($stdout)
5
5
  require_relative "resque_to_cloudwatch/config.rb"
6
6
  require_relative "resque_to_cloudwatch/cloudwatch_sender.rb"
7
7
  require_relative "resque_to_cloudwatch/graphite_sender.rb"
8
- require_relative "resque_to_cloudwatch/collector.rb"
8
+ require_relative "resque_to_cloudwatch/collectors.rb"
@@ -8,12 +8,12 @@ module ResqueToCloudwatch
8
8
  @config = config
9
9
  end
10
10
 
11
- def send_value(value)
11
+ def send_value(value, metric_name)
12
12
  cw = AWS::CloudWatch.new
13
13
  cw.client.put_metric_data({
14
- :namespace => "#{@config.namespace}/resque_queues",
14
+ :namespace => "#{@config.namespace}/resque",
15
15
  :metric_data => [
16
- :metric_name => "jobs_queued",
16
+ :metric_name => metric_name,
17
17
  :dimensions => [
18
18
  {
19
19
  :name => 'hostname',
@@ -28,7 +28,7 @@ module ResqueToCloudwatch
28
28
  :unit => 'Count'
29
29
  ]
30
30
  })
31
- $log.info "CloudwatchSender: Sent metric value #{value}"
31
+ $log.info "CloudwatchSender: Sent metric value #{value} for #{metric_name}"
32
32
  end
33
33
 
34
34
  def inspect
@@ -0,0 +1,48 @@
1
+ module ResqueToCloudwatch
2
+ class QueueLengthCollector
3
+
4
+ def initialize(config)
5
+ @config = config
6
+ end
7
+
8
+ def get_value
9
+ redis = Redis.new(:host => @config.redis_host, :port => @config.redis_port)
10
+ redis.smembers('resque:queues').map do |queue_key|
11
+ redis.llen("resque:queue:#{queue_key}")
12
+ end.reduce(:+)
13
+ end
14
+
15
+ def metric_name
16
+ "resque_queues"
17
+ end
18
+
19
+ def to_s
20
+ metric_name
21
+ end
22
+
23
+ end
24
+
25
+ class WorkersWorkingCollector
26
+
27
+ def initialize(config)
28
+ @config = config
29
+ end
30
+
31
+ def get_value
32
+ redis = Redis.new(:host => @config.redis_host, :port => @config.redis_port)
33
+ redis.smembers('resque:workers').select do |worker_key|
34
+ redis.exists("resque:worker:#{worker_key}")
35
+ end.length
36
+ end
37
+
38
+ def metric_name
39
+ "resque_workers_working"
40
+ end
41
+
42
+ def to_s
43
+ metric_name
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -8,12 +8,12 @@ module ResqueToCloudwatch
8
8
  @config = config
9
9
  end
10
10
 
11
- def send_value(value)
11
+ def send_value(value, metric_name)
12
12
  graphite = Graphite.new({:host => @config.graphite_host, :port => @config.graphite_port})
13
13
  graphite.send_metrics({
14
- "resque_to_cloudwatch.#{@config.namespace}.#{@config.hostname}.#{@config.project}" => value
14
+ "resque_to_cloudwatch.#{@config.namespace}.#{metric_name}.#{@config.hostname}.#{@config.project}" => value
15
15
  })
16
- $log.info "GraphiteSender: sent metric value #{value}"
16
+ $log.info "GraphiteSender: sent metric value #{value} for #{metric_name}"
17
17
  end
18
18
 
19
19
  def inspect
@@ -1,3 +1,3 @@
1
1
  module ResqueToCloudwatch
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_to_cloudwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Sykes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,7 +113,7 @@ files:
113
113
  - config.yaml
114
114
  - lib/resque_to_cloudwatch.rb
115
115
  - lib/resque_to_cloudwatch/cloudwatch_sender.rb
116
- - lib/resque_to_cloudwatch/collector.rb
116
+ - lib/resque_to_cloudwatch/collectors.rb
117
117
  - lib/resque_to_cloudwatch/config.rb
118
118
  - lib/resque_to_cloudwatch/graphite_sender.rb
119
119
  - lib/resque_to_cloudwatch/version.rb
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.1.10
141
+ rubygems_version: 2.1.11
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Submit Resque queue lengths to AWS Cloudwatch
@@ -1,16 +0,0 @@
1
- module ResqueToCloudwatch
2
- class Collector
3
-
4
- def initialize(config)
5
- @config = config
6
- end
7
-
8
- def get_queue_length
9
- redis = Redis.new(:host => @config.redis_host, :port => @config.redis_port)
10
- redis.smembers('resque:queues').map do |queue_key|
11
- redis.llen("resque:queue:#{queue_key}")
12
- end.reduce(:+)
13
- end
14
-
15
- end
16
- end