sidekiq-health 0.1.0

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: b81bb187af9420b1b278749905046150a361654f
4
+ data.tar.gz: 443e051e0878485318ff55fbe74407bfad37140f
5
+ SHA512:
6
+ metadata.gz: b960ef54e38a0e2ca11672028d1cf6f1419c20caeac60b461890ad3e1d2155b62df48af8a68b25793dc2ff2dddad9ba61df603fbd0b20c6922fd435b2af99ad4
7
+ data.tar.gz: 112593760a8daeb7e2cd5bff5481acea4ff6692ce6050dd52df364237538716489b559a844a97ae803f8c71233949befd7cbb4cd20fec2a2b956fd56228aadb7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.7
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sidekiq-health.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tom de Vries
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Sidekiq::Health
2
+
3
+ Sidekiq::Health prints the size of your Sidekiq Queues with either an `OK` or `WARNING` tag, the queue name and size. The current threshold is set to 50 meaning that when there are more than 49 jobs enqueued Sidekiq::Health will mark the queue as "too busy".
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sidekiq-health'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sidekiq-health
20
+
21
+ ## Requirements
22
+
23
+ Sidekiq::Health expects you to have the default Sidekiq configuration file located in `config/sidekiq.yml`.
24
+
25
+ NOTE: Only names queues are supported at this time.
26
+
27
+ ## Usage
28
+
29
+ Sidekiq::Health is intended to be used within a Rails project. When added to your project's Gemfile a rake task will be added:
30
+
31
+ $ rake sidekiq::queue::status
32
+
33
+ Which, depending on your `config/sidekiq.yml` and state of Sidekiq will result in:
34
+
35
+ ```
36
+ WARNING: TOO MANY JOBS ENQUEUED. Queue: "mailers" Size: 75
37
+ OK. Queue: "default" Size: 0
38
+ ```
39
+ Match the "WARNING" with your favorite monitoring tool and escalate accordingly.
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tomdev/sidekiq-health.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
55
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sidekiq/health"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require 'yaml'
2
+
3
+ module Sidekiq
4
+ module Health
5
+ class QueueNames
6
+ attr_reader :configuration
7
+
8
+ SIDEKIQ_CONFIGURATION_FILE_PATH = 'config/sidekiq.yml'
9
+
10
+ def initialize(configuration_file_path = SIDEKIQ_CONFIGURATION_FILE_PATH)
11
+ @configuration = YAML.load_file(configuration_file_path)
12
+ end
13
+
14
+ def get
15
+ configuration[:queues].map { |q| q.is_a?(Array) ? q[0] : q }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,53 @@
1
+ require 'sidekiq/api'
2
+
3
+ module Sidekiq
4
+ module Health
5
+ class QueueStatus
6
+ def print
7
+ output = ""
8
+
9
+ queue_names.each do |name|
10
+ output << "\n" unless output == ""
11
+ output << QueueHealthFormatter.new(name, queue_size(name)).to_s
12
+ end
13
+
14
+ output
15
+ end
16
+
17
+ private
18
+
19
+ def queue_size(name)
20
+ Sidekiq::Queue.new(name).size
21
+ end
22
+
23
+ def queue_names
24
+ Sidekiq::Health::QueueNames.new.get
25
+ end
26
+ end
27
+
28
+ class QueueHealthFormatter
29
+ QUEUE_SIZE_WARNING_THRESHOLD = 50
30
+
31
+ attr_reader :name, :size
32
+
33
+ def initialize(name, size)
34
+ @name = name
35
+ @size = size
36
+ end
37
+
38
+ def to_s
39
+ if size < QUEUE_SIZE_WARNING_THRESHOLD
40
+ "OK. #{queue_information}"
41
+ else
42
+ "WARNING: TOO MANY JOBS ENQUEUED. #{queue_information}"
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def queue_information
49
+ "Queue: \"#{name}\" Size: #{size}"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+ require 'sidekiq/health'
2
+
3
+ module Sidekiq
4
+ module Health
5
+ require 'rails'
6
+
7
+ class Railtie < ::Rails::Railtie
8
+ rake_tasks { load "sidekiq/tasks/sidekiq_health.rake" }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Sidekiq
2
+ module Health
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'sidekiq/health/railtie' if defined?(Rails::Railtie)
2
+
3
+ module Sidekiq
4
+ module Health
5
+ LIBRARY_PATH = File.join(File.dirname(__FILE__), 'health')
6
+ GEM_PATH = File.dirname(__FILE__)
7
+
8
+ %w{
9
+ queue_names
10
+ queue_status
11
+ version
12
+ }.each {|lib| require File.join(LIBRARY_PATH, lib) }
13
+ end
14
+ end
15
+
@@ -0,0 +1,8 @@
1
+ namespace :sidekiq do
2
+ namespace :queue do
3
+ desc "Output current queue size of all Sidekiq queues"
4
+ task :status => :environment do
5
+ puts Sidekiq::Health::QueueStatus.new.print
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sidekiq/health/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidekiq-health"
8
+ spec.version = Sidekiq::Health::VERSION
9
+ spec.authors = ["Tom de Vries"]
10
+ spec.email = ["tom@hackerone.com"]
11
+
12
+ spec.summary = %q{Monitor the size of your Sidekiq queues.}
13
+ spec.description = %q{Sidekiq::Health adds a rake task that outputs the
14
+ current size our your Sidekiq queues.}
15
+ spec.homepage = "https://github.com/tomdev/sidekiq-health"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
19
+ # delete this section to allow pushing this gem to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "railties", "~> 4.0"
35
+ spec.add_development_dependency "sidekiq", "~> 3.0"
36
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-health
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom de Vries
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-25 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sidekiq
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: |-
84
+ Sidekiq::Health adds a rake task that outputs the
85
+ current size our your Sidekiq queues.
86
+ email:
87
+ - tom@hackerone.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/sidekiq/health.rb
102
+ - lib/sidekiq/health/queue_names.rb
103
+ - lib/sidekiq/health/queue_status.rb
104
+ - lib/sidekiq/health/railtie.rb
105
+ - lib/sidekiq/health/version.rb
106
+ - lib/sidekiq/tasks/sidekiq_health.rake
107
+ - sidekiq-health.gemspec
108
+ homepage: https://github.com/tomdev/sidekiq-health
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.2.5
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Monitor the size of your Sidekiq queues.
133
+ test_files: []