health-monitor-rails 6.0.0 → 7.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 +78 -1
- data/app/controllers/health_monitor/health_controller.rb +20 -10
- data/app/views/health_monitor/health/check.html.erb +79 -0
- data/lib/health_monitor/monitor.rb +8 -11
- data/lib/health_monitor/providers/base.rb +1 -1
- data/lib/health_monitor/providers/redis.rb +1 -1
- data/lib/health_monitor/providers/sidekiq.rb +5 -1
- data/lib/health_monitor/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4686976a383f5c4b5e85369cfc0c752e4caddc8
|
4
|
+
data.tar.gz: 15031a662f7188298f468ef51bb6c63dc862884d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdf0b7c905ee120037d83b864b163b6da1c80b27c859a24efa24e5ed5acde6386cbacfe539cc7b917a2ec56888584b8c8b14080c81350320ac206fe923685986
|
7
|
+
data.tar.gz: 1d74eed9701d6c17d112564d5526783ce6026c5757396181ea0caa7a820f4d604e6168061dfbb52dd89e8769b3e71c3e52c87ff35109ec67c54e5df45d3f9178
|
data/README.md
CHANGED
@@ -7,7 +7,84 @@
|
|
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. The method will return an appropriate HTTP status as well as
|
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
|
+
|
12
|
+
## Examples
|
13
|
+
|
14
|
+
### HTML Status Page
|
15
|
+
|
16
|
+

|
17
|
+
|
18
|
+
### JSON response
|
19
|
+
|
20
|
+
```bash
|
21
|
+
>> curl -s http://localhost:3000/check.json | json_pp
|
22
|
+
```
|
23
|
+
|
24
|
+
```json
|
25
|
+
{
|
26
|
+
"timestamp" : "2017-03-10 17:07:52 +0200",
|
27
|
+
"status" : "ok",
|
28
|
+
"results" : [
|
29
|
+
{
|
30
|
+
"name" : "Database",
|
31
|
+
"message" : "",
|
32
|
+
"status" : "OK"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"status" : "OK",
|
36
|
+
"message" : "",
|
37
|
+
"name" : "Cache"
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"status" : "OK",
|
41
|
+
"message" : "",
|
42
|
+
"name" : "Redis"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"status" : "OK",
|
46
|
+
"message" : "",
|
47
|
+
"name" : "Sidekiq"
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
```
|
52
|
+
|
53
|
+
### XML response
|
54
|
+
|
55
|
+
```bash
|
56
|
+
>> curl -s http://localhost:3000/check.xml
|
57
|
+
```
|
58
|
+
|
59
|
+
```xml
|
60
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
61
|
+
<hash>
|
62
|
+
<results type="array">
|
63
|
+
<result>
|
64
|
+
<name>Database</name>
|
65
|
+
<message></message>
|
66
|
+
<status>OK</status>
|
67
|
+
</result>
|
68
|
+
<result>
|
69
|
+
<name>Cache</name>
|
70
|
+
<message></message>
|
71
|
+
<status>OK</status>
|
72
|
+
</result>
|
73
|
+
<result>
|
74
|
+
<name>Redis</name>
|
75
|
+
<message></message>
|
76
|
+
<status>OK</status>
|
77
|
+
</result>
|
78
|
+
<result>
|
79
|
+
<name>Sidekiq</name>
|
80
|
+
<message></message>
|
81
|
+
<status>OK</status>
|
82
|
+
</result>
|
83
|
+
</results>
|
84
|
+
<status type="symbol">ok</status>
|
85
|
+
<timestamp>2017-03-10 17:08:50 +0200</timestamp>
|
86
|
+
</hash>
|
87
|
+
```
|
11
88
|
|
12
89
|
## Setup
|
13
90
|
|
@@ -6,22 +6,32 @@ module HealthMonitor
|
|
6
6
|
before_action :authenticate_with_basic_auth
|
7
7
|
end
|
8
8
|
|
9
|
-
# GET /health/check
|
10
9
|
def check
|
11
|
-
|
12
|
-
|
13
|
-
HealthMonitor.configuration.environment_variables ||= {}
|
14
|
-
v = HealthMonitor.configuration.environment_variables.merge(time: Time.now.to_s(:db))
|
15
|
-
env_vars = [environment_variables: v]
|
16
|
-
res[:results] = env_vars + res[:results]
|
10
|
+
@statuses = statuses
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
respond_to do |format|
|
13
|
+
format.html
|
14
|
+
format.json do
|
15
|
+
render json: statuses
|
16
|
+
end
|
17
|
+
format.xml do
|
18
|
+
render xml: statuses
|
19
|
+
end
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def statuses
|
26
|
+
res = HealthMonitor.check(request: request)
|
27
|
+
res.merge(env_vars)
|
28
|
+
end
|
29
|
+
|
30
|
+
def env_vars
|
31
|
+
v = HealthMonitor.configuration.environment_variables || {}
|
32
|
+
v.empty? ? {} : { environment_variables: v }
|
33
|
+
end
|
34
|
+
|
25
35
|
def authenticate_with_basic_auth
|
26
36
|
return true unless HealthMonitor.configuration.basic_auth_credentials
|
27
37
|
|
@@ -0,0 +1,79 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Status</title>
|
5
|
+
<meta charset="utf-8">
|
6
|
+
<meta name="viewport" content="width=device-width">
|
7
|
+
<style type="text/css" media="screen">
|
8
|
+
body {
|
9
|
+
line-height: 2rem;
|
10
|
+
font-family: sans;
|
11
|
+
font-size: 14px;
|
12
|
+
background-color: #f0f0f0;
|
13
|
+
margin: 0;
|
14
|
+
padding: 0;
|
15
|
+
color: #000;
|
16
|
+
text-align: center;
|
17
|
+
}
|
18
|
+
|
19
|
+
a { color: #333; }
|
20
|
+
|
21
|
+
.container {
|
22
|
+
width: 960px;
|
23
|
+
margin: 20px auto;
|
24
|
+
text-align: left;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-weight: normal;
|
29
|
+
line-height: 2.8rem;
|
30
|
+
font-size: 30px;
|
31
|
+
letter-spacing: -1px;
|
32
|
+
text-align: center;
|
33
|
+
color: #333;
|
34
|
+
}
|
35
|
+
|
36
|
+
.container {
|
37
|
+
width: 960px;
|
38
|
+
margin:40px auto;
|
39
|
+
overflow: hidden;
|
40
|
+
}
|
41
|
+
|
42
|
+
.statuses {
|
43
|
+
background: #FFF;
|
44
|
+
width: 100%;
|
45
|
+
border-radius: 5px;
|
46
|
+
}
|
47
|
+
.statuses h1 { border-radius: 5px 5px 0 0; background: #f9f9f9; padding: 10px; border-bottom: 1px solid #eee;}
|
48
|
+
.statuses .status { font-size: 14px; border-bottom: 1px solid #eee; padding: 15px; }
|
49
|
+
.statuses .status:last-child { border-bottom: 0px; }
|
50
|
+
.statuses .name { font-size: 20px; margin-right: 20px; min-width: 100px; font-weight: bold; color: #555; }
|
51
|
+
.statuses .state { font-size: 14px; float: right; width: 80px; color: #45b81d; }
|
52
|
+
.statuses .message { color: #666; }
|
53
|
+
.statuses .timestamp { width: 130px; color: #999; }
|
54
|
+
.statuses .status-error .state { color: red; }
|
55
|
+
|
56
|
+
.powered { text-align: center; margin-top: 10px; color: #aaa; }
|
57
|
+
.powered a { color: #666; }
|
58
|
+
</style>
|
59
|
+
</head>
|
60
|
+
|
61
|
+
<body>
|
62
|
+
<div class="container">
|
63
|
+
<div class="statuses">
|
64
|
+
<h1>Status Page</h1>
|
65
|
+
<% @statuses[:results].each do |status| %>
|
66
|
+
<div class="status status-<%= status[:status].downcase %>">
|
67
|
+
<div class="status-heading">
|
68
|
+
<span class="name"><%= status[:name] %></span>
|
69
|
+
<span class="state"><%= status[:status] %></span>
|
70
|
+
</div>
|
71
|
+
<div class="message"><%= status[:message] %></div>
|
72
|
+
</div>
|
73
|
+
<% end %>
|
74
|
+
</div>
|
75
|
+
<div class="powered">
|
76
|
+
Powered by <a href="https://github.com/lbeder/health-monitor-rails" target="_blank">health-monitor-rails</a>
|
77
|
+
</div>
|
78
|
+
</div>
|
79
|
+
</body>
|
@@ -21,7 +21,8 @@ module HealthMonitor
|
|
21
21
|
|
22
22
|
{
|
23
23
|
results: results,
|
24
|
-
status: results.all? { |res| res
|
24
|
+
status: results.all? { |res| res[:status] == STATUSES[:ok] } ? :ok : :service_unavailable,
|
25
|
+
timestamp: Time.now.to_s(:rfc2822)
|
25
26
|
}
|
26
27
|
end
|
27
28
|
|
@@ -32,21 +33,17 @@ module HealthMonitor
|
|
32
33
|
monitor.check!
|
33
34
|
|
34
35
|
{
|
35
|
-
provider.provider_name
|
36
|
-
|
37
|
-
|
38
|
-
timestamp: Time.now.to_s(:db)
|
39
|
-
}
|
36
|
+
name: provider.provider_name,
|
37
|
+
message: '',
|
38
|
+
status: STATUSES[:ok]
|
40
39
|
}
|
41
40
|
rescue => e
|
42
41
|
configuration.error_callback.call(e) if configuration.error_callback
|
43
42
|
|
44
43
|
{
|
45
|
-
provider.provider_name
|
46
|
-
|
47
|
-
|
48
|
-
timestamp: Time.now.to_s(:db)
|
49
|
-
}
|
44
|
+
name: provider.provider_name,
|
45
|
+
message: e.message,
|
46
|
+
status: STATUSES[:error]
|
50
47
|
}
|
51
48
|
end
|
52
49
|
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: 7.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: 2017-
|
11
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -220,6 +220,34 @@ dependencies:
|
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: capybara
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: capybara-screenshot
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
223
251
|
description: Health monitoring Rails plug-in, which checks various services (db, cache,
|
224
252
|
sidekiq, redis, etc.).
|
225
253
|
email:
|
@@ -231,6 +259,7 @@ files:
|
|
231
259
|
- README.md
|
232
260
|
- Rakefile
|
233
261
|
- app/controllers/health_monitor/health_controller.rb
|
262
|
+
- app/views/health_monitor/health/check.html.erb
|
234
263
|
- config/routes.rb
|
235
264
|
- lib/health-monitor-rails.rb
|
236
265
|
- lib/health_monitor/configuration.rb
|