health-monitor-rails 8.1.0 → 8.3.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 +61 -0
- data/app/controllers/health_monitor/health_controller.rb +5 -1
- data/lib/health-monitor-rails.rb +0 -4
- data/lib/health_monitor/monitor.rb +7 -2
- data/lib/health_monitor/providers/delayed_job.rb +1 -1
- data/lib/health_monitor/providers/sidekiq.rb +24 -13
- data/lib/health_monitor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d71ec5ebaa809a23436eae3e97ab65b13f6a9ce
|
4
|
+
data.tar.gz: 5babeadd3fd6ee6c39cefe18057082a0f119bbfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57d6d72d415c2922eb1108a4a037a160d24b229be501915ccabe0f7550ac30cd34bac899efc964802e5c188c989d955bc60a0f9961ebbcafe918fa7ccf6b34aa
|
7
|
+
data.tar.gz: 76d9aa1af004e01451e7730052570e476faf75aca9e27ced22e0a0785c564c11ba5437f6bda4393d1a1f4399035c7443bec579e129fa5d3a953ce943f8066013
|
data/README.md
CHANGED
@@ -9,6 +9,8 @@ This is a health monitoring Rails mountable plug-in, which checks various servic
|
|
9
9
|
|
10
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 an HTML/JSON/XML response representing the state of each provider.
|
11
11
|
|
12
|
+
You can filter which checks to run by passing a parameter called ```providers```.
|
13
|
+
|
12
14
|
## Examples
|
13
15
|
|
14
16
|
### HTML Status Page
|
@@ -50,6 +52,31 @@ Mounting this gem will add a '/check' route to your application, which can be us
|
|
50
52
|
}
|
51
53
|
```
|
52
54
|
|
55
|
+
### Filtered JSON Response
|
56
|
+
|
57
|
+
```bash
|
58
|
+
>> curl -s http://localhost:3000/check.json?providers[]=database&providers[]=redis | json_pp
|
59
|
+
```
|
60
|
+
|
61
|
+
```json
|
62
|
+
{
|
63
|
+
"timestamp" : "2017-03-10 17:07:52 +0200",
|
64
|
+
"status" : "ok",
|
65
|
+
"results" : [
|
66
|
+
{
|
67
|
+
"name" : "Database",
|
68
|
+
"message" : "",
|
69
|
+
"status" : "OK"
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"status" : "OK",
|
73
|
+
"message" : "",
|
74
|
+
"name" : "Redis"
|
75
|
+
},
|
76
|
+
]
|
77
|
+
}
|
78
|
+
```
|
79
|
+
|
53
80
|
### XML Response
|
54
81
|
|
55
82
|
```bash
|
@@ -86,6 +113,32 @@ Mounting this gem will add a '/check' route to your application, which can be us
|
|
86
113
|
</hash>
|
87
114
|
```
|
88
115
|
|
116
|
+
### Filtered XML Response
|
117
|
+
|
118
|
+
```bash
|
119
|
+
>> curl -s http://localhost:3000/check.xml?providers[]=database&providers[]=redis
|
120
|
+
```
|
121
|
+
|
122
|
+
```xml
|
123
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
124
|
+
<hash>
|
125
|
+
<results type="array">
|
126
|
+
<result>
|
127
|
+
<name>Database</name>
|
128
|
+
<message></message>
|
129
|
+
<status>OK</status>
|
130
|
+
</result>
|
131
|
+
<result>
|
132
|
+
<name>Redis</name>
|
133
|
+
<message></message>
|
134
|
+
<status>OK</status>
|
135
|
+
</result>
|
136
|
+
</results>
|
137
|
+
<status type="symbol">ok</status>
|
138
|
+
<timestamp>2017-03-10 17:08:50 +0200</timestamp>
|
139
|
+
</hash>
|
140
|
+
```
|
141
|
+
|
89
142
|
## Setup
|
90
143
|
|
91
144
|
If you are using bundler add health-monitor-rails to your Gemfile:
|
@@ -157,6 +210,14 @@ HealthMonitor.configure do |config|
|
|
157
210
|
sidekiq_config.queue_size = 50
|
158
211
|
end
|
159
212
|
end
|
213
|
+
|
214
|
+
# To configure specific queues
|
215
|
+
HealthMonitor.configure do |config|
|
216
|
+
config.sidekiq.configure do |sidekiq_config|
|
217
|
+
sidekiq_config.add_queue_configuration("critical", latency: 10.seconds, size: 20)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
160
221
|
```
|
161
222
|
|
162
223
|
```ruby
|
@@ -25,7 +25,7 @@ module HealthMonitor
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def statuses
|
28
|
-
res = HealthMonitor.check(request: request)
|
28
|
+
res = HealthMonitor.check(request: request, params: providers_params)
|
29
29
|
res.merge(env_vars)
|
30
30
|
end
|
31
31
|
|
@@ -42,5 +42,9 @@ module HealthMonitor
|
|
42
42
|
name == credentials[:username] && password == credentials[:password]
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
def providers_params
|
47
|
+
params.permit(providers: [])
|
48
|
+
end
|
45
49
|
end
|
46
50
|
end
|
data/lib/health-monitor-rails.rb
CHANGED
@@ -16,8 +16,13 @@ module HealthMonitor
|
|
16
16
|
yield configuration if block_given?
|
17
17
|
end
|
18
18
|
|
19
|
-
def check(request: nil)
|
20
|
-
|
19
|
+
def check(request: nil, params: {})
|
20
|
+
providers = configuration.providers
|
21
|
+
if params[:providers].present?
|
22
|
+
providers = providers.select { |provider| params[:providers].include?(provider.provider_name.downcase) }
|
23
|
+
end
|
24
|
+
|
25
|
+
results = providers.map { |provider| provider_result(provider, request) }
|
21
26
|
|
22
27
|
{
|
23
28
|
results: results,
|
@@ -7,14 +7,25 @@ module HealthMonitor
|
|
7
7
|
|
8
8
|
class Sidekiq < Base
|
9
9
|
class Configuration
|
10
|
+
DEFAULT_QUEUE_NAME = 'default'.freeze
|
10
11
|
DEFAULT_LATENCY_TIMEOUT = 30
|
11
12
|
DEFAULT_QUEUES_SIZE = 100
|
12
13
|
|
13
|
-
attr_accessor :latency, :queue_size
|
14
|
+
attr_accessor :latency, :queue_size, :queue_name
|
15
|
+
attr_reader :queues
|
14
16
|
|
15
17
|
def initialize
|
18
|
+
@queue_name = DEFAULT_QUEUE_NAME
|
16
19
|
@latency = DEFAULT_LATENCY_TIMEOUT
|
17
20
|
@queue_size = DEFAULT_QUEUES_SIZE
|
21
|
+
@queues = {}
|
22
|
+
@queues[queue_name] = { latency: latency, queue_size: queue_size }
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_queue_configuration(queue_name, latency: DEFAULT_LATENCY_TIMEOUT, queue_size: DEFAULT_QUEUES_SIZE)
|
26
|
+
raise SidekiqException.new('Queue name is mandatory') if queue_name.blank?
|
27
|
+
|
28
|
+
queues[queue_name] = { latency: latency, queue_size: queue_size }
|
18
29
|
end
|
19
30
|
end
|
20
31
|
|
@@ -25,7 +36,7 @@ module HealthMonitor
|
|
25
36
|
check_queue_size!
|
26
37
|
check_redis!
|
27
38
|
rescue Exception => e
|
28
|
-
raise SidekiqException.new(e
|
39
|
+
raise SidekiqException.new(e)
|
29
40
|
end
|
30
41
|
|
31
42
|
private
|
@@ -50,19 +61,18 @@ module HealthMonitor
|
|
50
61
|
end
|
51
62
|
|
52
63
|
def check_latency!
|
53
|
-
|
54
|
-
|
55
|
-
return unless latency > configuration.latency
|
64
|
+
configuration.queues.each do |queue, config|
|
65
|
+
latency = queue(queue).latency
|
56
66
|
|
57
|
-
|
67
|
+
raise "queue '#{queue}': latency #{latency} is greater than #{config[:latency]}" if latency > config[:latency]
|
68
|
+
end
|
58
69
|
end
|
59
70
|
|
60
71
|
def check_queue_size!
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
raise "queue size #{size} is greater than #{configuration.queue_size}"
|
72
|
+
configuration.queues.each do |queue, config|
|
73
|
+
size = queue(queue).size
|
74
|
+
raise "queue '#{queue}': size #{size} is greater than #{config[:queue_size]}" if size > config[:queue_size]
|
75
|
+
end
|
66
76
|
end
|
67
77
|
|
68
78
|
def check_redis!
|
@@ -73,8 +83,9 @@ module HealthMonitor
|
|
73
83
|
end
|
74
84
|
end
|
75
85
|
|
76
|
-
|
77
|
-
@queue ||=
|
86
|
+
def queue(queue_name)
|
87
|
+
@queue ||= {}
|
88
|
+
@queue[queue_name] ||= ::Sidekiq::Queue.new(queue_name)
|
78
89
|
end
|
79
90
|
end
|
80
91
|
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: 8.
|
4
|
+
version: 8.3.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: 2018-
|
11
|
+
date: 2018-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|