health-monitor-rails 9.3.0 → 10.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -4
- data/app/controllers/health_monitor/health_controller.rb +1 -0
- data/app/views/health_monitor/health/check.html.erb +7 -5
- data/lib/health_monitor/configuration.rb +6 -1
- data/lib/health_monitor/providers/base.rb +8 -2
- data/lib/health_monitor/providers/database.rb +9 -2
- data/lib/health_monitor/providers/redis.rb +16 -8
- data/lib/health_monitor/providers/sidekiq.rb +2 -0
- data/lib/health_monitor/version.rb +1 -1
- metadata +40 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0502db2e6a54cf73defc3f9333fe3a157c79d8b5b2a4122fd65b6f54c48c76c5
|
4
|
+
data.tar.gz: 1b1a0591c7660abf3d38f8b0dd5c21761125f5a9da46bfc3283b2a46f49d40a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc7cd0673bf3c88b9ba7e146c171aee8a98630205b65b1603e1ed39b161bb288cd76a0875ea977725a30bf8914adb4a60232d71be6882e7c865239c364931af2
|
7
|
+
data.tar.gz: bb1e311ee5dabda3fa4c1bd141467caf1c7469ba1c1873189e5f3c165ad8c7387c930ccdb94122fcce6d54359a7ae84dea58d3f200b1ce14a51616030589fb9f
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# health-monitor-rails
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/health-monitor-rails.svg)](http://badge.fury.io/rb/health-monitor-rails)
|
4
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/lbeder/health-monitor-rails/actions/workflows/ci.yml/badge.svg)](https://github.com/lbeder/health-monitor-rails/actions/workflows/ci.yml)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/lbeder/health-monitor-rails/badge.svg)](https://coveralls.io/r/lbeder/health-monitor-rails)
|
6
6
|
|
7
7
|
This is a health monitoring Rails mountable plug-in, which checks various services (db, cache, sidekiq, redis, etc.).
|
@@ -214,7 +214,7 @@ HealthMonitor.configure do |config|
|
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
|
-
#
|
217
|
+
# Sidekiq with specific queues
|
218
218
|
HealthMonitor.configure do |config|
|
219
219
|
config.sidekiq.configure do |sidekiq_config|
|
220
220
|
sidekiq_config.add_queue_configuration('critical', latency: 10.seconds, queue_size: 20)
|
@@ -224,7 +224,7 @@ end
|
|
224
224
|
```
|
225
225
|
|
226
226
|
```ruby
|
227
|
-
# Redis
|
227
|
+
# Redis with existing connection
|
228
228
|
HealthMonitor.configure do |config|
|
229
229
|
config.redis.configure do |redis_config|
|
230
230
|
redis_config.connection = Redis.current # Use your custom redis connection
|
@@ -236,7 +236,7 @@ end
|
|
236
236
|
Additionally, you can configure an explicit URL:
|
237
237
|
|
238
238
|
```ruby
|
239
|
-
# Redis
|
239
|
+
# Redis with a URL configuration
|
240
240
|
HealthMonitor.configure do |config|
|
241
241
|
config.redis.configure do |redis_config|
|
242
242
|
redis_config.url = 'redis://user:pass@example.redis.com:90210/'
|
@@ -245,12 +245,25 @@ HealthMonitor.configure do |config|
|
|
245
245
|
end
|
246
246
|
```
|
247
247
|
|
248
|
+
Or via a connection pool:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
# Redis using Connection Pools
|
252
|
+
HealthMonitor.configure do |config|
|
253
|
+
config.redis.configure do |redis_config|
|
254
|
+
redis_config.connection = ConnectionPool.new(size: 5) { Redis.new } # Use your custom connection pool
|
255
|
+
end
|
256
|
+
end
|
257
|
+
```
|
258
|
+
|
248
259
|
The currently supported settings are:
|
249
260
|
|
250
261
|
#### Sidekiq
|
251
262
|
|
252
263
|
* `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).
|
253
264
|
* `queue_size`: the size (maximum) of a queue which is considered unhealthy (the default is 100).
|
265
|
+
* `default_queue`: the default queue to check.
|
266
|
+
* `add_queue_configuration`: add specific configuration per queue.
|
254
267
|
|
255
268
|
#### Redis
|
256
269
|
|
@@ -69,10 +69,12 @@
|
|
69
69
|
</div>
|
70
70
|
</div>
|
71
71
|
</main>
|
72
|
-
|
73
|
-
<
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
<% if !@hide_footer %>
|
73
|
+
<footer>
|
74
|
+
<div class="font-light text-center text-slate-500 text-xs px-5">
|
75
|
+
Powered by <a href="https://github.com/lbeder/health-monitor-rails" target="_blank">health-monitor-rails</a>
|
76
|
+
</div>
|
77
|
+
</footer>
|
78
|
+
<% end %>
|
77
79
|
</body>
|
78
80
|
</html>
|
@@ -7,6 +7,7 @@ module HealthMonitor
|
|
7
7
|
attr_accessor :basic_auth_credentials,
|
8
8
|
:environment_variables,
|
9
9
|
:error_callback,
|
10
|
+
:hide_footer,
|
10
11
|
:path
|
11
12
|
attr_reader :providers
|
12
13
|
|
@@ -21,7 +22,11 @@ module HealthMonitor
|
|
21
22
|
PROVIDERS.each do |provider_name|
|
22
23
|
define_method provider_name do |&_block|
|
23
24
|
require "health_monitor/providers/#{provider_name}"
|
24
|
-
|
25
|
+
|
26
|
+
add_provider(
|
27
|
+
"HealthMonitor::Providers::#{provider_name.to_s.titleize.delete(' ')}"
|
28
|
+
.constantize
|
29
|
+
)
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module HealthMonitor
|
4
4
|
module Providers
|
5
5
|
class Base
|
6
|
+
@global_configuration = nil
|
7
|
+
|
6
8
|
attr_reader :request
|
7
9
|
attr_accessor :configuration
|
8
10
|
|
@@ -10,10 +12,14 @@ module HealthMonitor
|
|
10
12
|
@provider_name ||= name.demodulize
|
11
13
|
end
|
12
14
|
|
15
|
+
def self.global_configuration
|
16
|
+
@global_configuration ||= configuration_class.new
|
17
|
+
end
|
18
|
+
|
13
19
|
def self.configure
|
14
20
|
return unless configurable?
|
15
21
|
|
16
|
-
@global_configuration
|
22
|
+
@global_configuration ||= configuration_class.new
|
17
23
|
|
18
24
|
yield @global_configuration if block_given?
|
19
25
|
end
|
@@ -23,7 +29,7 @@ module HealthMonitor
|
|
23
29
|
|
24
30
|
return unless self.class.configurable?
|
25
31
|
|
26
|
-
self.configuration = self.class.
|
32
|
+
self.configuration = self.class.global_configuration
|
27
33
|
end
|
28
34
|
|
29
35
|
# @abstract
|
@@ -8,8 +8,15 @@ module HealthMonitor
|
|
8
8
|
|
9
9
|
class Database < Base
|
10
10
|
def check!
|
11
|
-
|
12
|
-
|
11
|
+
failed_databases = []
|
12
|
+
|
13
|
+
ActiveRecord::Base.connection_handler.all_connection_pools.each do |cp|
|
14
|
+
cp.connection.check_version
|
15
|
+
rescue Exception
|
16
|
+
failed_databases << cp.db_config.name
|
17
|
+
end
|
18
|
+
|
19
|
+
raise "unable to connect to: #{failed_databases.uniq.join(',')}" unless failed_databases.empty?
|
13
20
|
rescue Exception => e
|
14
21
|
raise DatabaseException.new(e.message)
|
15
22
|
end
|
@@ -4,6 +4,8 @@ require 'health_monitor/providers/base'
|
|
4
4
|
|
5
5
|
module HealthMonitor
|
6
6
|
module Providers
|
7
|
+
CONNECTION_POOL_SIZE = 1
|
8
|
+
|
7
9
|
class RedisException < StandardError; end
|
8
10
|
|
9
11
|
class Redis < Base
|
@@ -23,6 +25,10 @@ module HealthMonitor
|
|
23
25
|
def configuration_class
|
24
26
|
::HealthMonitor::Providers::Redis::Configuration
|
25
27
|
end
|
28
|
+
|
29
|
+
def as_connection_pool(connection)
|
30
|
+
ConnectionPool.new(size: CONNECTION_POOL_SIZE) { connection }
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
def check!
|
@@ -30,8 +36,6 @@ module HealthMonitor
|
|
30
36
|
check_max_used_memory!
|
31
37
|
rescue Exception => e
|
32
38
|
raise RedisException.new(e.message)
|
33
|
-
ensure
|
34
|
-
redis.close
|
35
39
|
end
|
36
40
|
|
37
41
|
private
|
@@ -39,8 +43,8 @@ module HealthMonitor
|
|
39
43
|
def check_values!
|
40
44
|
time = Time.now.to_formatted_s(:rfc2822)
|
41
45
|
|
42
|
-
redis.set(key, time)
|
43
|
-
fetched = redis.get(key)
|
46
|
+
redis.with { |conn| conn.set(key, time) }
|
47
|
+
fetched = redis.with { |conn| conn.get(key) }
|
44
48
|
|
45
49
|
raise "different values (now: #{time}, fetched: #{fetched})" if fetched != time
|
46
50
|
end
|
@@ -59,11 +63,15 @@ module HealthMonitor
|
|
59
63
|
def redis
|
60
64
|
@redis =
|
61
65
|
if configuration.connection
|
62
|
-
configuration.connection
|
66
|
+
if configuration.connection.is_a?(ConnectionPool)
|
67
|
+
configuration.connection
|
68
|
+
else
|
69
|
+
ConnectionPool.new(size: CONNECTION_POOL_SIZE) { configuration.connection }
|
70
|
+
end
|
63
71
|
elsif configuration.url
|
64
|
-
::Redis.new(url: configuration.url)
|
72
|
+
ConnectionPool.new(size: CONNECTION_POOL_SIZE) { ::Redis.new(url: configuration.url) }
|
65
73
|
else
|
66
|
-
::Redis.new
|
74
|
+
ConnectionPool.new(size: CONNECTION_POOL_SIZE) { ::Redis.new }
|
67
75
|
end
|
68
76
|
end
|
69
77
|
|
@@ -72,7 +80,7 @@ module HealthMonitor
|
|
72
80
|
end
|
73
81
|
|
74
82
|
def used_memory_mb
|
75
|
-
bytes_to_megabytes(redis.info['used_memory'])
|
83
|
+
bytes_to_megabytes(redis.with { |conn| conn.info['used_memory'] })
|
76
84
|
end
|
77
85
|
end
|
78
86
|
end
|
@@ -73,6 +73,7 @@ module HealthMonitor
|
|
73
73
|
|
74
74
|
def check_processes!
|
75
75
|
sidekiq_stats = ::Sidekiq::Stats.new
|
76
|
+
|
76
77
|
return unless sidekiq_stats.processes_size.zero?
|
77
78
|
|
78
79
|
raise 'Sidekiq alive processes number is 0!'
|
@@ -89,6 +90,7 @@ module HealthMonitor
|
|
89
90
|
def check_queue_size!
|
90
91
|
configuration.queues.each do |queue, config|
|
91
92
|
size = queue(queue).size
|
93
|
+
|
92
94
|
raise "queue '#{queue}': size #{size} is greater than #{config[:queue_size]}" if size > config[:queue_size]
|
93
95
|
end
|
94
96
|
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:
|
4
|
+
version: 10.0.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:
|
11
|
+
date: 2023-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: appraisal
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: coveralls_reborn
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '4.1'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: mock_redis
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: pry
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,19 +137,19 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: rake
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: resque
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,14 +184,42 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '0
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop-rake
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
188
202
|
type: :development
|
189
203
|
prerelease: false
|
190
204
|
version_requirements: !ruby/object:Gem::Requirement
|
191
205
|
requirements:
|
192
206
|
- - ">="
|
193
207
|
- !ruby/object:Gem::Version
|
194
|
-
version: '0
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: rubocop-rspec
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
195
223
|
- !ruby/object:Gem::Dependency
|
196
224
|
name: sidekiq
|
197
225
|
requirement: !ruby/object:Gem::Requirement
|