health-monitor-rails 7.3.1 → 7.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c698297ece6c817cca14cdf047d7576933d68f2
4
- data.tar.gz: 024b1a433db3fe3ac5b6a7a54cc316a2f5870fe3
3
+ metadata.gz: 85424832894f22b0c7ea378d9f196b5391b75309
4
+ data.tar.gz: 4a94ec537d24ec741d9aff84123541abd8a9995a
5
5
  SHA512:
6
- metadata.gz: 72366f5c346f6fabb6bde9f89cc5b6ce8dec8d55bed144b2dc405bb27ad1d1d820d8712e1e6ebc2b85c0fb0b2e01ec3ee7eb38b891280c7d23f0c6ff1e1dcd63
7
- data.tar.gz: d8e9aade1d886309b1a9d5a57c45d756144fe6cd626894ee98784a982dcddce7edebdb783a564ab354a9f4f004988f60ff3bba4929cdff115eae717a1a4d8a1b
6
+ metadata.gz: 42aae7d82352be072f1aaa67465cb83bb2643fc372b79d3ebb7699aefe9638b191c9becf834c0e0f138f8a0d64a281e3edb410d8d8dc56aad972a4e9b772a866
7
+ data.tar.gz: 8895295d39d649d1c53a7a1256d72d7fe4f797ca25d3e323a2b6819cc5c68138b93d381323c2ddbb1000554198fa25b7e681ec86452d4bfaf9b41342517eb065
data/README.md CHANGED
@@ -148,17 +148,21 @@ end
148
148
  Some of the providers can also accept additional configuration:
149
149
 
150
150
  ```ruby
151
+ # Sidekiq
151
152
  HealthMonitor.configure do |config|
152
153
  config.sidekiq.configure do |sidekiq_config|
153
154
  sidekiq_config.latency = 3.hours
155
+ sidekiq_config.queue_size = 50
154
156
  end
155
157
  end
156
158
  ```
157
159
 
158
160
  ```ruby
161
+ # Redis
159
162
  HealthMonitor.configure do |config|
160
163
  config.redis.configure do |redis_config|
161
- redis_config.url = 'redis://user:pass@example.redis.com:90210/'
164
+ redis_config.connection = Redis.current # use your custom redis connection
165
+ redis_config.url = 'redis://user:pass@example.redis.com:90210/' # or URL
162
166
  end
163
167
  end
164
168
  ```
@@ -168,11 +172,12 @@ The currently supported settings are:
168
172
  #### Sidekiq
169
173
 
170
174
  * `latency`: the latency (in seconds) of a queue (now - when the oldest job was enqueued) which is considered unhealthy (the default is 30 seconds, but larger processing queue should have a larger latency value).
175
+ * `queue_size`: the size (maximim) of a queue which is considered unhealthy (the default is 100).
171
176
 
172
177
  #### Redis
173
178
 
174
179
  * `url`: the url used to connect to your Redis instance - note, this is an optional configuration and will use the default connection if not specified
175
-
180
+ * `connection`: Use custom redis connection (e.g., `Redis.current`).
176
181
 
177
182
  ### Adding a Custom Provider
178
183
  It's also possible to add custom health check providers suited for your needs (of course, it's highly appreciated and encouraged if you'd contribute useful providers to the project).
@@ -8,7 +8,7 @@ module HealthMonitor
8
8
  class Configuration
9
9
  DEFAULT_URL = nil
10
10
 
11
- attr_accessor :url
11
+ attr_accessor :url, :connection
12
12
 
13
13
  def initialize
14
14
  @url = DEFAULT_URL
@@ -26,7 +26,6 @@ module HealthMonitor
26
26
  def check!
27
27
  time = Time.now.to_s(:rfc2822)
28
28
 
29
- redis = configuration.url ? ::Redis.new(url: configuration.url) : ::Redis.new
30
29
  redis.set(key, time)
31
30
  fetched = redis.get(key)
32
31
 
@@ -42,6 +41,17 @@ module HealthMonitor
42
41
  def key
43
42
  @key ||= ['health', request.try(:remote_ip)].join(':')
44
43
  end
44
+
45
+ def redis
46
+ @redis =
47
+ if configuration.connection
48
+ configuration.connection
49
+ elsif configuration.url
50
+ ::Redis.new(url: configuration.url)
51
+ else
52
+ ::Redis.new
53
+ end
54
+ end
45
55
  end
46
56
  end
47
57
  end
@@ -8,11 +8,13 @@ module HealthMonitor
8
8
  class Sidekiq < Base
9
9
  class Configuration
10
10
  DEFAULT_LATENCY_TIMEOUT = 30
11
+ DEFAULT_QUEUES_SIZE = 100
11
12
 
12
- attr_accessor :latency
13
+ attr_accessor :latency, :queue_size
13
14
 
14
15
  def initialize
15
16
  @latency = DEFAULT_LATENCY_TIMEOUT
17
+ @queue_size = DEFAULT_QUEUES_SIZE
16
18
  end
17
19
  end
18
20
 
@@ -20,6 +22,7 @@ module HealthMonitor
20
22
  check_workers!
21
23
  check_processes!
22
24
  check_latency!
25
+ check_queue_size!
23
26
  check_redis!
24
27
  rescue Exception => e
25
28
  raise SidekiqException.new(e.message)
@@ -47,13 +50,21 @@ module HealthMonitor
47
50
  end
48
51
 
49
52
  def check_latency!
50
- latency = ::Sidekiq::Queue.new.latency
53
+ latency = queue.latency
51
54
 
52
55
  return unless latency > configuration.latency
53
56
 
54
57
  raise "latency #{latency} is greater than #{configuration.latency}"
55
58
  end
56
59
 
60
+ def check_queue_size!
61
+ size = queue.size
62
+
63
+ return unless size > configuration.queue_size
64
+
65
+ raise "queue size #{size} is greater than #{configuration.queue_size}"
66
+ end
67
+
57
68
  def check_redis!
58
69
  if ::Sidekiq.respond_to?(:redis_info)
59
70
  ::Sidekiq.redis_info
@@ -61,6 +72,10 @@ module HealthMonitor
61
72
  ::Sidekiq.redis(&:info)
62
73
  end
63
74
  end
75
+
76
+ private def queue
77
+ @queue ||= ::Sidekiq::Queue.new
78
+ end
64
79
  end
65
80
  end
66
81
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HealthMonitor
4
- VERSION = '7.3.1'.freeze
4
+ VERSION = '7.4.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health-monitor-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.1
4
+ version: 7.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Beder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-22 00:00:00.000000000 Z
11
+ date: 2017-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
173
+ version: '0.5'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: '0.5'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: sidekiq
183
183
  requirement: !ruby/object:Gem::Requirement