system_health 0.0.5 → 0.0.7
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 +60 -47
- data/lib/system_health/monitor.rb +1 -1
- data/lib/system_health/monitors/sql.rb +17 -0
- data/lib/system_health/version.rb +1 -1
- data/spec/lib/system_health/monitor_spec.rb +16 -3
- 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: 64fc6a4ae13390505cc788003d0689e4852b9a65
|
4
|
+
data.tar.gz: 079ac177a733ba941db774c4c4b5232c48358b8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa659c4506bf06cb2dede60f15166187802e239ffbe407282ca1e38165dcb89a92c759efd8e6b953f25805dbff4552d208d3e6328453a0b6be02986c177aed5e
|
7
|
+
data.tar.gz: db1c220f31218da8bb7f7d5fd0365dbf5edd0a9bb6727292ab0e55915197a59fc19335b64dc40ec6cec3e0f7491108884916a517f360594f3b0d7c041900e604
|
data/README.md
CHANGED
@@ -2,11 +2,7 @@
|
|
2
2
|
|
3
3
|
The System Health gem can be added to your Rails application to provide
|
4
4
|
a convenient way to regularly look for bad data or other system health
|
5
|
-
indicators.
|
6
|
-
count and enumerate error messages. This count and the messages can be
|
7
|
-
collected by external monitoring tools that look for the HTTP status code
|
8
|
-
(200 when there are no errors or 500 when there is at least one error)
|
9
|
-
and/or inspect the JSON payload that is returned.
|
5
|
+
indicators.
|
10
6
|
|
11
7
|
## Installation
|
12
8
|
|
@@ -24,81 +20,98 @@ Or install it yourself as:
|
|
24
20
|
|
25
21
|
and then...
|
26
22
|
|
27
|
-
1.
|
23
|
+
1. Create your monitor classes
|
24
|
+
|
25
|
+
All monitoring classes require a public instance method named `description`.
|
26
|
+
This method should return a string describing the bad data condition that is
|
27
|
+
being tested.
|
28
|
+
|
29
|
+
## Generic monitoring class
|
30
|
+
|
31
|
+
For example, in lib/system_health/monitors/bad_data.rb create:
|
28
32
|
|
29
33
|
```ruby
|
30
|
-
SystemHealth
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
module SystemHealth
|
35
|
+
module Monitors
|
36
|
+
class BadData < Base
|
37
|
+
def description
|
38
|
+
'Bad data was discovered'
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def bad_data?
|
44
|
+
# return true from this method if there is bad data
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
34
48
|
end
|
35
49
|
```
|
36
50
|
|
37
|
-
|
38
|
-
|
51
|
+
define a private instance method `bad_data?` that should return true
|
52
|
+
when bad data exists.
|
39
53
|
|
40
|
-
|
54
|
+
## SQL monitoring class
|
41
55
|
|
42
|
-
|
56
|
+
For example, in lib/system_health/monitors/bad_sql_data.rb create:
|
43
57
|
|
44
58
|
```ruby
|
45
59
|
module SystemHealth
|
46
60
|
module Monitors
|
47
|
-
class
|
48
|
-
def
|
49
|
-
|
61
|
+
class BadSqlData < Sql
|
62
|
+
def description
|
63
|
+
'Bad data was discovered through a SQL query'
|
50
64
|
end
|
51
65
|
|
52
66
|
private
|
53
67
|
|
54
|
-
def
|
55
|
-
|
68
|
+
def sql
|
69
|
+
<<-SQL
|
70
|
+
SELECT *
|
71
|
+
FROM some_table
|
72
|
+
WHERE bad_data is true
|
73
|
+
SQL
|
56
74
|
end
|
57
75
|
end
|
58
76
|
end
|
59
77
|
end
|
60
78
|
```
|
61
79
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
80
|
+
this type of monitor requires an additional private instance method
|
81
|
+
named `sql`. This SQL statement should return rows for any data
|
82
|
+
integrity problem. I.e. no rows means no problem. Rows returned means
|
83
|
+
there is a problem.
|
66
84
|
|
67
|
-
3. Define the environment variables
|
68
85
|
|
69
|
-
|
86
|
+
2. create an initializer in config/initializers/system_health.rb
|
70
87
|
|
71
|
-
```
|
72
|
-
|
73
|
-
|
88
|
+
```ruby
|
89
|
+
SystemHealth.configure do |config|
|
90
|
+
config.monitor_classes = [
|
91
|
+
SystemHealth::Monitors::BadData,
|
92
|
+
SystemHealth::Monitors::BadSqlData
|
93
|
+
]
|
94
|
+
end
|
74
95
|
```
|
75
96
|
|
76
|
-
on other environments, you'll need to define these elsewhere.
|
77
|
-
|
78
97
|
## Usage
|
79
98
|
|
80
|
-
The System Health gem exposes a
|
81
|
-
|
82
|
-
|
83
|
-
It will return a 200 HTTP status code if there are no errors and a 500
|
84
|
-
HTTP status code if there are any errors. It also returns a JSON
|
85
|
-
payload with data like this:
|
99
|
+
The System Health gem exposes a monitoring class `SystemHealth::Monitor` that
|
100
|
+
can be used to test for all system health issues with the following
|
101
|
+
methods:
|
86
102
|
|
87
|
-
```
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
}
|
103
|
+
```ruby
|
104
|
+
mon = SystemHealth::Monitor.new
|
105
|
+
mon.error_messages
|
106
|
+
mon.error_count
|
92
107
|
```
|
93
108
|
|
94
109
|
## To do?
|
95
110
|
|
96
|
-
1.
|
97
|
-
|
98
|
-
2. Add
|
99
|
-
|
100
|
-
3. Add the ability to generate error notifications directly from System
|
101
|
-
Health instead of relying on external monitoring tools to send these
|
111
|
+
1. Add concept of notifiers to make it more seamless to email or report
|
112
|
+
on system health issues.
|
113
|
+
2. Add monitor classes so different classes can be run at different
|
114
|
+
times and with different frequency.
|
102
115
|
|
103
116
|
## Contributing
|
104
117
|
|
@@ -7,8 +7,14 @@ module SystemHealth
|
|
7
7
|
|
8
8
|
context 'when errors' do
|
9
9
|
class MonitorDouble < Monitors::Base
|
10
|
-
def
|
11
|
-
|
10
|
+
def description
|
11
|
+
'hello'
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def bad_data?
|
17
|
+
true
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
@@ -36,7 +42,14 @@ module SystemHealth
|
|
36
42
|
|
37
43
|
context 'when no errors' do
|
38
44
|
class MonitorDouble < Monitors::Base
|
39
|
-
def
|
45
|
+
def description
|
46
|
+
'hello'
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def bad_data?
|
52
|
+
false
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: system_health
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stirling Olson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/system_health/engine.rb
|
86
86
|
- lib/system_health/monitor.rb
|
87
87
|
- lib/system_health/monitors/base.rb
|
88
|
+
- lib/system_health/monitors/sql.rb
|
88
89
|
- lib/system_health/version.rb
|
89
90
|
- spec/lib/system_health/monitor_spec.rb
|
90
91
|
- system_health.gemspec
|