sidekiq_queue_status 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32426fcdf33231d81705398d85a9202f7a172f6a
4
+ data.tar.gz: 30bd276ea5ece5a0abfbb330285527d407db13c0
5
+ SHA512:
6
+ metadata.gz: d4fc67ee170af880100f568e93cbf84f5a2d29a28854495bcaad7ada6295db37f4115275d21ae5b9910d868ec351cd3faea3312b1bfd7b693cf45fa079ffb2a0
7
+ data.tar.gz: 2d3b2e1e5011dfa927a1d32d99df7f7ed4c7908a2ea7586a4a1e18911e44812d5b6ebc2ff294fa10257877b64dd39e1e0eca2ca275034ee767f57bbf3d85c136
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/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matthijs Langenberg
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Sidekiq Queue Status
2
+
3
+ Rails Middleware to add `/queue-status` endpoint. Useful for pinging
4
+ services such as Icinga or Nagios.
5
+
6
+ Lists latency for each sidekiq queue. The latency is the number of
7
+ seconds the oldest job (next in line) is waiting to be performed.
8
+
9
+ Under normal circumstances returns a `200 OK` status code. When latency
10
+ is higher than the 30s default threshold, a `503 Service Unavailable` is
11
+ returned.
12
+
13
+ Thresholds are configurable by setting `config.queue_tresholds` hash.
14
+ Key is queue name, value is latency threshold in seconds.
15
+
16
+ Response body is a JSON object, listing the latencies of all queues and
17
+ an array of error messages explaining which queues triggered a threshold
18
+ error.
19
+
20
+ ```json
21
+ {
22
+ "latencies": {
23
+ "batch": 200,
24
+ "default": 1
25
+ },
26
+ "errors": ["Queue batch above threshold of 100"]
27
+ }
28
+ ```
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ gem 'sidekiq_queue_status'
35
+
36
+ And then execute:
37
+
38
+ $ bundle
39
+
40
+ Or install it yourself as:
41
+
42
+ $ gem install sidekiq_queue_status
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( http://github.com/nedap/sidekiq_queue_status/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,35 @@
1
+ require 'sidekiq/api'
2
+
3
+ module SidekiqQueueStatus
4
+ class Middleware
5
+ DEFAULT_TRESHOLD = 30
6
+ HEADERS = {
7
+ 'Content-Type' => 'application/json',
8
+ 'Cache-Control' => 'no-cache'
9
+ }
10
+
11
+ def initialize(app, configured_tresholds)
12
+ @app = app
13
+ @latency_treshold = Hash.new(DEFAULT_TRESHOLD).merge(configured_tresholds)
14
+ end
15
+
16
+ def call(env)
17
+ if env["PATH_INFO"] =~ %r{\A/queue-status\Z}
18
+ errors = []
19
+ queues.each do |name, latency|
20
+ max_latency = @latency_treshold[name]
21
+ errors << "Queue #{name} above threshold of #{max_latency}s" if latency > max_latency
22
+ end
23
+ body = { latencies: queues, errors: errors }.to_json
24
+ status = errors.any? ? 503 : 200
25
+ [status, HEADERS, [body]]
26
+ else
27
+ @app.call(env)
28
+ end
29
+ end
30
+
31
+ def queues
32
+ Sidekiq::Queue.all.map { |q| [q.name, q.latency.to_i] }.to_h
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails/railtie'
2
+
3
+ module SidekiqQueueStatus
4
+ class Railtie < Rails::Railtie
5
+ config.queue_tresholds = {}
6
+ initializer "sidekiq_queue_status.configure_rails_initialization" do |app|
7
+ app.middleware.use SidekiqQueueStatus::Middleware, app.config.queue_tresholds
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module SidekiqQueueStatus
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'sidekiq_queue_status/version'
2
+ require 'sidekiq_queue_status/middleware'
3
+ require 'sidekiq_queue_status/railtie'
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sidekiq_queue_status/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidekiq_queue_status"
8
+ spec.version = SidekiqQueueStatus::VERSION
9
+ spec.authors = ["Matthijs Langenberg"]
10
+ spec.email = ["mlangenberg@gmail.com"]
11
+ spec.summary = %q{Monitor Sidekiq queue status in Rails}
12
+ spec.description = %q{
13
+ This Gem adds a /queue-status endpoint to your Rails app.
14
+ Useful for monitoring your Sidekiq queues with Icinga or Nagios.
15
+ Normally returns a 200 OK, returns 503 Service Unavailable
16
+ when stats such as queue latency are too high.
17
+ }
18
+ spec.homepage = "https://github.com/nedap/sidekiq_queue_status"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files`.split($/)
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "railties", "> 3.0"
25
+ spec.add_dependency "sidekiq", "> 2.5"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.5"
28
+ spec.add_development_dependency "rake"
29
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq_queue_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthijs Langenberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>'
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>'
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sidekiq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>'
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>'
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: "\n This Gem adds a /queue-status endpoint
70
+ to your Rails app.\n Useful for monitoring your Sidekiq
71
+ queues with Icinga or Nagios.\n Normally returns a 200
72
+ OK, returns 503 Service Unavailable\n when stats such
73
+ as queue latency are too high.\n "
74
+ email:
75
+ - mlangenberg@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - .gitignore
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - lib/sidekiq_queue_status.rb
86
+ - lib/sidekiq_queue_status/middleware.rb
87
+ - lib/sidekiq_queue_status/railtie.rb
88
+ - lib/sidekiq_queue_status/version.rb
89
+ - sidekiq_queue_status.gemspec
90
+ homepage: https://github.com/nedap/sidekiq_queue_status
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Monitor Sidekiq queue status in Rails
114
+ test_files: []
115
+ has_rdoc: