health-monitor-rails 1.1.0 → 2.0.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.
- checksums.yaml +4 -4
- data/README.md +17 -4
- data/lib/health_monitor/configuration.rb +13 -2
- data/lib/health_monitor/providers/base.rb +21 -0
- data/lib/health_monitor/providers/sidekiq.rb +17 -3
- data/lib/health_monitor/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 202a4502ef0b79a948915e6511a598166b3399ed
|
4
|
+
data.tar.gz: a7901956e05d4dd6a56e675f84e2f5eb9e027c65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9e374e7f8f4b40a945dbe94b9cc2b0d970124d5bd8d03d5ac3ad683f4f96fb12ec0e4b4833fe3be35be0d950d77c9add29f264af460f1d4d508f33489131d5c
|
7
|
+
data.tar.gz: c4743ec2a9839f826db25622825ccdd823c03b93859f0f391fd820f92fe20a8e2345837d4ef07f3ccbd57de6b3f07ae3beb5b922a6535ccdcff61affa7a2e5b8
|
data/README.md
CHANGED
@@ -47,21 +47,34 @@ The following services are currently supported:
|
|
47
47
|
## Configuration
|
48
48
|
|
49
49
|
### Adding providers
|
50
|
-
By default, only the database check is enabled. You can add more service providers via an initializer:
|
50
|
+
By default, only the database check is enabled. You can add more service providers by explicitly enabling them via an initializer:
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
HealthMonitor.configure do |config|
|
54
|
-
config.
|
54
|
+
config.cache
|
55
|
+
config.redis
|
56
|
+
config.sidekiq
|
55
57
|
end
|
56
58
|
```
|
57
59
|
|
58
|
-
|
60
|
+
### Providers configuration
|
61
|
+
|
62
|
+
Some of the providers can also accept additional configuration:
|
63
|
+
|
59
64
|
```ruby
|
60
65
|
HealthMonitor.configure do |config|
|
61
|
-
config.
|
66
|
+
config.sidekiq.configure do |sidekiq_config|
|
67
|
+
sidekiq_config.latency = 3.hours
|
68
|
+
end
|
62
69
|
end
|
63
70
|
```
|
64
71
|
|
72
|
+
The currently supported settings are:
|
73
|
+
|
74
|
+
#### Sidekiq
|
75
|
+
|
76
|
+
* `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).
|
77
|
+
|
65
78
|
### Adding a custom error callback
|
66
79
|
If you need to perform any additional error handling (for example, for additional error reporting), you can configure a custom error callback:
|
67
80
|
|
@@ -1,9 +1,20 @@
|
|
1
1
|
module HealthMonitor
|
2
2
|
class Configuration
|
3
|
-
|
3
|
+
PROVIDERS = [:cache, :database, :redis, :resque, :sidekiq].freeze
|
4
|
+
|
5
|
+
attr_accessor :error_callback, :basic_auth_credentials
|
6
|
+
attr_reader :providers
|
4
7
|
|
5
8
|
def initialize
|
6
|
-
@providers = [:database]
|
9
|
+
@providers = Set.new([:database])
|
10
|
+
end
|
11
|
+
|
12
|
+
PROVIDERS.each do |provider|
|
13
|
+
define_method provider do |&block|
|
14
|
+
@providers << provider
|
15
|
+
|
16
|
+
"HealthMonitor::Providers::#{provider.capitalize}".constantize
|
17
|
+
end
|
7
18
|
end
|
8
19
|
end
|
9
20
|
end
|
@@ -2,15 +2,36 @@ module HealthMonitor
|
|
2
2
|
module Providers
|
3
3
|
class Base
|
4
4
|
attr_reader :request
|
5
|
+
cattr_accessor :configuration
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
return unless configurable?
|
9
|
+
|
10
|
+
self.configuration ||= configuration_class.new
|
11
|
+
|
12
|
+
yield self.configuration if block_given?
|
13
|
+
end
|
5
14
|
|
6
15
|
def initialize(request: nil)
|
7
16
|
@request = request
|
17
|
+
|
18
|
+
self.class.configure
|
8
19
|
end
|
9
20
|
|
10
21
|
# @abstract
|
11
22
|
def check!
|
12
23
|
raise NotImplementedError
|
13
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.configurable?
|
29
|
+
configuration_class
|
30
|
+
end
|
31
|
+
|
32
|
+
# @abstract
|
33
|
+
def self.configuration_class
|
34
|
+
end
|
14
35
|
end
|
15
36
|
end
|
16
37
|
end
|
@@ -3,11 +3,19 @@ require 'sidekiq/api'
|
|
3
3
|
|
4
4
|
module HealthMonitor
|
5
5
|
module Providers
|
6
|
-
LATENCY_TIMEOUT = 30.freeze
|
7
|
-
|
8
6
|
class SidekiqException < StandardError; end
|
9
7
|
|
10
8
|
class Sidekiq < Base
|
9
|
+
class Configuration
|
10
|
+
DEFAULT_LATENCY_TIMEOUT = 30.freeze
|
11
|
+
|
12
|
+
attr_accessor :latency
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@latency = DEFAULT_LATENCY_TIMEOUT
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
11
19
|
def check!
|
12
20
|
check_workers!
|
13
21
|
check_latency!
|
@@ -18,6 +26,10 @@ module HealthMonitor
|
|
18
26
|
|
19
27
|
private
|
20
28
|
|
29
|
+
def self.configuration_class
|
30
|
+
Configuration
|
31
|
+
end
|
32
|
+
|
21
33
|
def check_workers!
|
22
34
|
::Sidekiq::Workers.new.size
|
23
35
|
end
|
@@ -25,7 +37,9 @@ module HealthMonitor
|
|
25
37
|
def check_latency!
|
26
38
|
latency = ::Sidekiq::Queue.new.latency
|
27
39
|
|
28
|
-
|
40
|
+
if latency > self.configuration.latency
|
41
|
+
raise "latency #{latency} is greater than #{self.configuration.latency}"
|
42
|
+
end
|
29
43
|
end
|
30
44
|
|
31
45
|
def check_redis!
|
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: 2.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: 2015-
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -213,3 +213,4 @@ specification_version: 4
|
|
213
213
|
summary: Health monitoring Rails plug-in, which checks various services (db, cache,
|
214
214
|
sidekiq, redis, etc.)
|
215
215
|
test_files: []
|
216
|
+
has_rdoc:
|