resque_to_cloudwatch 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e949b35b475c33f8fa264dc21a61bf51edb30a0
4
+ data.tar.gz: af3e2f113f01ad65cf18382e94c98ea8d5620b9d
5
+ SHA512:
6
+ metadata.gz: 5079dd977ba6e3b4a28bdc94b5368d9789cdff22f18f2db8da401e2ad01db432793f8af58ed9ba8945d62143568746f23dc4aebcff099ca0d6dceb854f27c4b0
7
+ data.tar.gz: d0a740b9f7292c2633756aeddb4e56bd26f0976699b26359d6e0bbd2ccb4f26d245a1be53397b0470f3acc2cb748af85a90618ab813b62eb92935661134384d8
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ops-cloudwatchd
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andy Sykes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # resque_to_cloudwatch
2
+
3
+ This is a gem containing a daemon for submitting Resque queue lengths to AWS
4
+ Cloudwatch.
5
+
6
+ ## Usage
7
+
8
+ The daemon lives at `bin/resque_to_cloudwatch`, and takes only a single parameter:
9
+
10
+ bin/resque_to_cloudwatch --config /path/to/config.yaml
11
+
12
+ If you don't supply this parameter, the daemon will look for a config file in the
13
+ current directory.
14
+
15
+ The config file has the following format (in YAML):
16
+
17
+ access_key_id: asdfasfasd
18
+ secret_access_key: asdfasdfasf
19
+ region: us-west-2
20
+ project: testing
21
+ hostname: laptop
22
+ redis_host: some.redis.host
23
+ redis_port: 6379
24
+ period: 60
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'redis'
4
+ require 'eventmachine'
5
+ require 'optparse'
6
+ require_relative '../lib/resque_to_cloudwatch'
7
+
8
+ $log.info "Starting ResqueToCloudwatch"
9
+
10
+ options = {}
11
+
12
+ OptionParser.new do |opts|
13
+ opts.on("-c", "--config", "Config file to load") do |c|
14
+ options[:config] = c
15
+ end
16
+ end.parse!
17
+
18
+ options[:config] ||= "#{File.expand_path("../../config.yaml", __FILE__)}"
19
+ config = ResqueToCloudwatch::Config.new(options[:config])
20
+ collector = ResqueToCloudwatch::Collector.new(config)
21
+ sender = ResqueToCloudwatch::Sender.new(config)
22
+
23
+ $log.info "Entering EventMachine loop with period of #{config.period} seconds"
24
+
25
+ EventMachine.run do
26
+ EventMachine.add_periodic_timer(config.period) do
27
+ begin
28
+ sender.send_value(collector.get_queue_length)
29
+ rescue => e
30
+ $log.error "Exception sending or collecting data: #{e.message}"
31
+ end
32
+ end
33
+ end
data/config.yaml ADDED
@@ -0,0 +1,8 @@
1
+ access_key_id: asdf
2
+ secret_access_key: asdf
3
+ region: us-west-2
4
+ project: testing
5
+ hostname: andy-laptop
6
+ redis_host: some.redis.host
7
+ redis_port: 6379
8
+ period: 60
@@ -0,0 +1,6 @@
1
+ require 'logger'
2
+ $log = Logger.new(STDOUT)
3
+
4
+ require_relative "resque_to_cloudwatch/config.rb"
5
+ require_relative "resque_to_cloudwatch/sender.rb"
6
+ require_relative "resque_to_cloudwatch/collector.rb"
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+ require 'aws-sdk'
3
+
4
+ module ResqueToCloudwatch
5
+ class Config
6
+
7
+ attr_reader :access_key_id, :secret_access_key, :project, :period, :region
8
+ attr_reader :redis_host, :redis_port, :hostname
9
+
10
+ def initialize(path)
11
+ $log.info "Loading configuration"
12
+ raise "Config file #{path} not found or readable" unless File.exists?(path)
13
+ @required_opts = %w{access_key_id secret_access_key project period region redis_host redis_port hostname}
14
+ @hash = YAML.load_file(path)
15
+ raise "Config file #{path} is empty" unless @hash
16
+ validate_config
17
+ @required_opts.each do |opt|
18
+ instance_variable_set("@#{opt}", @hash[opt])
19
+ $log.info "Config parameter: #{opt} is #{@hash[opt]}"
20
+ end
21
+
22
+ # Set up AWS credentials
23
+ AWS.config(
24
+ :access_key_id => @hash['access_key_id'],
25
+ :secret_access_key => @hash['secret_access_key'],
26
+ :region => @hash['region']
27
+ )
28
+ end
29
+
30
+ private
31
+
32
+ def validate_config
33
+ missing_opts = @required_opts.select do |opt|
34
+ @hash[opt].nil?
35
+ end
36
+ raise "Missing options: #{missing_opts.join(", ")}" unless missing_opts.empty?
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ require 'aws-sdk'
2
+
3
+ module ResqueToCloudwatch
4
+ class Sender
5
+
6
+ # Pass an instance of CloudwatchToResque::Config
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def send_value(value)
12
+ cw = AWS::CloudWatch.new
13
+ cw.client.put_metric_data({
14
+ :namespace => 'F3D/resque_queues',
15
+ :metric_data => [
16
+ :metric_name => "jobs_queued",
17
+ :dimensions => [
18
+ {
19
+ :name => 'hostname',
20
+ :value => @config.hostname
21
+ },
22
+ {
23
+ :name => 'project',
24
+ :value => @config.project
25
+ }
26
+ ],
27
+ :value => value,
28
+ :unit => 'Count'
29
+ ]
30
+ })
31
+ $log.info "Sent metric value #{value}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module ResqueToCloudwatch
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'resque_to_cloudwatch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "resque_to_cloudwatch"
8
+ spec.version = ResqueToCloudwatch::VERSION
9
+ spec.authors = ["Andy Sykes"]
10
+ spec.email = ["github@tinycat.co.uk"]
11
+ spec.description = %q{Submit Resque queue lengths to Cloudwatch}
12
+ spec.summary = %q{Submit Resque queue lengths to AWS Cloudwatch}
13
+ spec.homepage = "https://github.com/forward3d/resque_to_cloudwatch"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "aws-sdk", "= 1.24.0"
25
+ spec.add_dependency "eventmachine", "= 1.0.3"
26
+ spec.add_dependency "redis", "= 3.0.6"
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque_to_cloudwatch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andy Sykes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.24.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.24.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: eventmachine
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: redis
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.6
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.6
83
+ description: Submit Resque queue lengths to Cloudwatch
84
+ email:
85
+ - github@tinycat.co.uk
86
+ executables:
87
+ - resque_to_cloudwatch
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .ruby-gemset
93
+ - .ruby-version
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/resque_to_cloudwatch
99
+ - config.yaml
100
+ - lib/resque_to_cloudwatch.rb
101
+ - lib/resque_to_cloudwatch/collector.rb
102
+ - lib/resque_to_cloudwatch/config.rb
103
+ - lib/resque_to_cloudwatch/sender.rb
104
+ - lib/resque_to_cloudwatch/version.rb
105
+ - resque_to_cloudwatch.gemspec
106
+ homepage: https://github.com/forward3d/resque_to_cloudwatch
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.1.10
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Submit Resque queue lengths to AWS Cloudwatch
130
+ test_files: []