librato-sidekiq 0.1.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.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/History.md ADDED
@@ -0,0 +1,8 @@
1
+ librato-sidekiq changelog
2
+ =====================
3
+
4
+ HEAD
5
+ =======
6
+ - Initial commit
7
+ - Each completed job measures current stats, timing, and increments processed for queue and worker name
8
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Scott Klein <scott@statuspage.io>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ librato-sidekiq
2
+ =====
3
+
4
+ librato-sidekiq is a simple gem to stick Sidekiq stats and granular processing counts/times into [Librato Metrics](http://metrics.librato.com/)
5
+
6
+
7
+ Requirements and Compatibility
8
+ ------------
9
+
10
+ Gems:
11
+
12
+ * sidekiq
13
+ * librato-rails
14
+
15
+ Compatibility (tested):
16
+
17
+ * Ruby 2.0.0
18
+
19
+ (if you can confirm another version of Ruby, email me at scott@statuspage.io)
20
+
21
+
22
+ Usage with Rails 3.x
23
+ ---------------------------
24
+
25
+ In your Gemfile:
26
+
27
+ ```ruby
28
+ gem 'librato-sidekiq'
29
+ ```
30
+
31
+ In `config/environments/librato_sidekiq.rb`:
32
+
33
+ ```ruby
34
+ # only needed for fine-tuning, gem will enable all metrics by default
35
+ Librato::Sidekiq::Middleware.configure do |c|
36
+ # only enable for production
37
+ c.enabled = Rails.env.production?
38
+
39
+ # only allow these 3 queues
40
+ c.whitelist_queues = %w(default cron notifications)
41
+
42
+ # ignore these worker classes
43
+ c.blacklist_classes = %w(CronSchedulerWorker NotificationCheckerWorker)
44
+ end
45
+ ```
46
+
47
+
48
+ Configuration
49
+ ------------------------
50
+ Librato::Sidekiq accepts the following options.
51
+
52
+ **enabled**: Boolean, true by default
53
+
54
+ **whitelist_queues**: Array, list of queue names that will be the only ones sent to Librato (optional)
55
+
56
+ **blacklist_queues**: Array, list of queue names that will not be sent to Librato (optional)
57
+
58
+ **whitelist_classes**: Array, list of worker classes that will be the only ones sent to Librato (optional)
59
+
60
+ **blacklist_queues**: Array, list of worker classes that will not be sent to Librato (optional)
61
+
62
+
63
+ Contributing
64
+ -------------
65
+
66
+ If you have a fix you wish to provide, please fork the code, fix in your local project and then send a pull request on github. Please ensure that you include a test which verifies your fix and update History.md with a one sentence description of your fix so you get credit as a contributor.
67
+
68
+
69
+ Thanks
70
+ ------------
71
+
72
+ Mike Perham - for creating [Sidekiq](http://github.com/mperham/sidekiq), a fantastic contribution to the ruby world
73
+
74
+ Librato - for a great [metrics service](http://metrics.librato.com)
75
+
76
+
77
+ Author
78
+ ----------
79
+
80
+ Scott Klein, scott@statuspage.io, [statuspage.io](https://www.statuspage.io), If you like and use this project, please check out the [StatusPage.io service](https://www.statuspage.io/tour) for your project or company
81
+
82
+
83
+ Copyright
84
+ -----------
85
+
86
+ Copyright (c) 2013 Scott Klein. See LICENSE for details.
@@ -0,0 +1,3 @@
1
+ require 'librato-sidekiq/middleware'
2
+
3
+ Librato::Sidekiq::Middleware.configure
@@ -0,0 +1,85 @@
1
+ module Librato
2
+ module Sidekiq
3
+ class Middleware
4
+ cattr_accessor :enabled do
5
+ true
6
+ end
7
+
8
+ cattr_accessor :whitelist_queues, :blacklist_queues, :whitelist_classes, :blacklist_classes do
9
+ []
10
+ end
11
+
12
+ def initialize(options = {})
13
+ self.reconfigure
14
+ end
15
+
16
+ def self.configure
17
+ yield(self) if block_given?
18
+ self.new # will call reconfigure
19
+ end
20
+
21
+ def options
22
+ {
23
+ :enabled => self.enabled,
24
+ :whitelist_queues => self.whitelist_queues,
25
+ :blacklist_queues => self.blacklist_queues,
26
+ :whitelist_classes => self.whitelist_classes,
27
+ :blacklist_classes => self.blacklist_classes
28
+ }
29
+ end
30
+
31
+ def reconfigure
32
+ # puts "Reconfiguring with: #{options}"
33
+ ::Sidekiq.configure_server do |config|
34
+ config.server_middleware do |chain|
35
+ chain.remove self.class
36
+ chain.add self.class, self.options
37
+ end
38
+ end
39
+ end
40
+
41
+ def call(worker_instance, msg, queue)
42
+ unless self.enabled
43
+ # puts "Gem not enabled"
44
+ yield
45
+ return
46
+ end
47
+
48
+ t = Time.now
49
+ yield
50
+ elapsed = (Time.now - t).to_f
51
+
52
+ queue_in_whitelist = self.whitelist_queues.nil? || self.whitelist_queues.empty? || self.whitelist_queues.include?(queue.to_s)
53
+ queue_in_blacklist = self.blacklist_queues.include?(queue.to_s)
54
+ class_in_whitelist = self.whitelist_classes.nil? || self.whitelist_classes.empty? || self.whitelist_classes.include?(worker_instance.class.to_s)
55
+ class_in_blacklist = self.blacklist_classes.include?(worker_instance.class.to_s)
56
+
57
+ # puts "#{worker_instance} #{queue} qw:#{queue_in_whitelist} qb:#{queue_in_blacklist} cw:#{class_in_whitelist} cb:#{class_in_blacklist}"
58
+
59
+ Librato.group 'sidekiq' do |sidekiq|
60
+ stats = ::Sidekiq::Stats.new
61
+
62
+ sidekiq.increment 'processed'
63
+
64
+ [:enqueued, :failed].each do |m|
65
+ sidekiq.measure m.to_s, stats.send(m)
66
+ end
67
+
68
+ return unless class_in_whitelist && !class_in_blacklist && queue_in_whitelist && !queue_in_blacklist
69
+ # puts "doing Librato insert"
70
+
71
+ sidekiq.group queue.to_s do |q|
72
+ q.increment 'processed'
73
+ q.timing 'time', elapsed
74
+ q.measure 'enqueued', stats.queues[queue]
75
+
76
+ q.group msg["class"].underscore do |w|
77
+ w.increment 'processed'
78
+ w.timing 'time', elapsed
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,5 @@
1
+ module Librato
2
+ module Sidekiq
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ require './lib/librato-sidekiq/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{librato-sidekiq}
5
+ s.version = Librato::Sidekiq::VERSION
6
+ s.license = "MIT"
7
+
8
+ s.authors = ["Scott Klein"]
9
+ s.description = %q{Sidekiq hooks to push stats into Librato}
10
+ s.email = %q{scott@statuspage.io}
11
+ s.files = Dir.glob("lib/**/*") + [
12
+ "LICENSE",
13
+ "README.md",
14
+ "History.md",
15
+ "Gemfile",
16
+ "librato-sidekiq.gemspec",
17
+ ]
18
+ s.homepage = %q{http://github.com/StatusPage/librato-sidekiq}
19
+ s.rdoc_options = ["--charset=UTF-8"]
20
+ s.require_paths = ["lib"]
21
+ s.summary = %q{Sidekiq hooks to push stats into Librato}
22
+ s.test_files = Dir.glob("test/**/*")
23
+ s.add_dependency(%q<sidekiq>, [">= 0"])
24
+ s.add_dependency(%q<librato-rails>, [">= 0"])
25
+ s.add_development_dependency(%q<mini_shoulda>, [">= 0"])
26
+ s.add_development_dependency(%q<mocha>, [">= 0"])
27
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: librato-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scott Klein
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sidekiq
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: librato-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mini_shoulda
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Sidekiq hooks to push stats into Librato
79
+ email: scott@statuspage.io
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - lib/librato-sidekiq/middleware.rb
85
+ - lib/librato-sidekiq/version.rb
86
+ - lib/librato-sidekiq.rb
87
+ - LICENSE
88
+ - README.md
89
+ - History.md
90
+ - Gemfile
91
+ - librato-sidekiq.gemspec
92
+ homepage: http://github.com/StatusPage/librato-sidekiq
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.25
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Sidekiq hooks to push stats into Librato
118
+ test_files: []