health-monitor-rails 3.0.2 → 4.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 +1 -1
- data/app/controllers/health_monitor/health_controller.rb +4 -6
- data/lib/health_monitor/monitor.rb +34 -6
- data/lib/health_monitor/providers/base.rb +4 -0
- data/lib/health_monitor/providers/cache.rb +1 -1
- data/lib/health_monitor/providers/redis.rb +1 -1
- data/lib/health_monitor/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43cd56ba93149b6cd9603a232f6d42e733244997
|
4
|
+
data.tar.gz: 53f5306701a6e8a9318aa27c65c1553f2ba39f97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2906eff933ec100b18abf659ac3e9143328f9f13d1460ef903b3ebac53c4964a32ea3a69d847c54fdea84d1b3d63622df504ce2d6973722aae1d7dc16116e42
|
7
|
+
data.tar.gz: 76f14766d0c328686449107a7e3532af95e1c058ba363b81f484e17fd8c16fd2f341560b00ecaa9acc70b850805ec272bc1488b02a7733f0118d3c61efa52d7d
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
This is a health monitoring Rails mountable plug-in, which checks various services (db, cache, sidekiq, redis, etc.).
|
9
9
|
|
10
|
-
Mounting this gem will add a '/check' route to your application, which can be used for health monitoring the application and its various services.
|
10
|
+
Mounting this gem will add a '/check' route to your application, which can be used for health monitoring the application and its various services. The method will return an appropriate HTTP status as well as a JSON array representing the state of each provider.
|
11
11
|
|
12
12
|
## Setup
|
13
13
|
|
@@ -8,13 +8,11 @@ module HealthMonitor
|
|
8
8
|
|
9
9
|
# GET /health/check
|
10
10
|
def check
|
11
|
-
HealthMonitor.check
|
11
|
+
res = HealthMonitor.check(request: request)
|
12
12
|
|
13
|
-
self.
|
14
|
-
self.
|
15
|
-
|
16
|
-
self.status = :service_unavailable
|
17
|
-
self.response_body = "Health check has failed: #{Time.now.to_s(:db)}, error: #{e.message}\n"
|
13
|
+
self.content_type = Mime::JSON
|
14
|
+
self.status = res[:status]
|
15
|
+
self.response_body = ActiveSupport::JSON.encode(res[:results])
|
18
16
|
end
|
19
17
|
|
20
18
|
private
|
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'health_monitor/configuration'
|
2
2
|
|
3
3
|
module HealthMonitor
|
4
|
+
STATUSES = {
|
5
|
+
ok: 'OK',
|
6
|
+
error: 'ERROR'
|
7
|
+
}.freeze
|
8
|
+
|
4
9
|
extend self
|
5
10
|
|
6
11
|
attr_accessor :configuration
|
@@ -11,15 +16,38 @@ module HealthMonitor
|
|
11
16
|
yield configuration if block_given?
|
12
17
|
end
|
13
18
|
|
14
|
-
def check
|
15
|
-
configuration.providers.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
def check(request: nil)
|
20
|
+
results = configuration.providers.map { |provider| provider_result(provider, request) }
|
21
|
+
|
22
|
+
{
|
23
|
+
results: results,
|
24
|
+
status: results.all? { |res| res.values.first[:status] == STATUSES[:ok] } ? :ok : :service_unavailable
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def provider_result(provider, request)
|
31
|
+
monitor = provider.new(request: request)
|
32
|
+
monitor.check!
|
33
|
+
|
34
|
+
{
|
35
|
+
provider.provider_name => {
|
36
|
+
message: '',
|
37
|
+
status: STATUSES[:ok],
|
38
|
+
timestamp: Time.now.to_s(:db)
|
39
|
+
}
|
40
|
+
}
|
19
41
|
rescue => e
|
20
42
|
configuration.error_callback.call(e) if configuration.error_callback
|
21
43
|
|
22
|
-
|
44
|
+
{
|
45
|
+
provider.provider_name => {
|
46
|
+
message: e.message,
|
47
|
+
status: STATUSES[:error],
|
48
|
+
timestamp: Time.now.to_s(:db)
|
49
|
+
}
|
50
|
+
}
|
23
51
|
end
|
24
52
|
end
|
25
53
|
|
@@ -11,7 +11,7 @@ module HealthMonitor
|
|
11
11
|
Rails.cache.write(key, time)
|
12
12
|
fetched = Rails.cache.read(key)
|
13
13
|
|
14
|
-
raise "different values (now: #{time}, fetched: #{fetched}" if fetched != time
|
14
|
+
raise "different values (now: #{time}, fetched: #{fetched})" if fetched != time
|
15
15
|
rescue Exception => e
|
16
16
|
raise CacheException.new(e.message)
|
17
17
|
end
|
@@ -13,7 +13,7 @@ module HealthMonitor
|
|
13
13
|
redis.set(key, time)
|
14
14
|
fetched = redis.get(key)
|
15
15
|
|
16
|
-
raise "different values (now: #{time}, fetched: #{fetched}" if fetched != time
|
16
|
+
raise "different values (now: #{time}, fetched: #{fetched})" if fetched != time
|
17
17
|
rescue Exception => e
|
18
18
|
raise RedisException.new(e.message)
|
19
19
|
ensure
|
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: 4.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-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: timecop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rediska
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
235
|
version: '0'
|
222
236
|
requirements: []
|
223
237
|
rubyforge_project:
|
224
|
-
rubygems_version: 2.4.
|
238
|
+
rubygems_version: 2.4.8
|
225
239
|
signing_key:
|
226
240
|
specification_version: 4
|
227
241
|
summary: Health monitoring Rails plug-in, which checks various services (db, cache,
|