system_health 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 649b6b51406bda1aec88b5865610daaf7886daf1
4
- data.tar.gz: 1155745115676abe0b455e8d672d97477594f958
3
+ metadata.gz: 64fc6a4ae13390505cc788003d0689e4852b9a65
4
+ data.tar.gz: 079ac177a733ba941db774c4c4b5232c48358b8f
5
5
  SHA512:
6
- metadata.gz: ce6bbd99f24675ef3e6b6a522905ee43cd73c5f406666cd9eefadf9cd97752a960ae5ade7f6177efe35517427c8ee72aeccf7eb5d65ca0719d5a1be01ac77359
7
- data.tar.gz: 139474d30143f8904c40ad0fc6e3ad86aace8e76a01878fafdc05bf3e27fc67eb310829021085131a4037bb3b158b969490d1fd784f278bc1b8340b41178c9c9
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. It provides a single endpoint that will generate an error
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. create an initializer in config/initializers/system_health.rb
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.configure do |config|
31
- config.monitor_classes = [
32
- SystemHealth::Monitors::BadData
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
- This should define the SYSTEM_HEALTH_MONITOR_CLASSES array with all
38
- your monitor classes. There can be as many monitor classes as you wish.
51
+ define a private instance method `bad_data?` that should return true
52
+ when bad data exists.
39
53
 
40
- 2. Create your monitor classes
54
+ ## SQL monitoring class
41
55
 
42
- In lib/system_health/monitors/bad_data.rb create:
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 BadData < Base
48
- def error_messages
49
- ['some error message here'] if bad_data?
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 bad_data?
55
- # logic here
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
- Each monitor should define a public instance method for `error_messages`
63
- as an array. If that array is empty then the data is good. When the
64
- data is bad, one or more error messages can be placed in that array.
65
- That is it!
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
- For applications hosted on Heroku, this might be something like:
86
+ 2. create an initializer in config/initializers/system_health.rb
70
87
 
71
- ```bash
72
- heroku config:add SYSTEM_HEALTH_MONITOR_USERNAME=somenamehere
73
- heroku config:add SYSTEM_HEALTH_MONITOR_PASSWORD=somesecrethere
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 single controller endpoint at:
81
- /system_health/monitor
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
- ```json
88
- {
89
- "error_count": 2,
90
- "messages": ["some error message here", "another error message"]
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. Consider how to deal with long running monitors that may fail with
97
- page load limits (e.g. Heroku's 30 second timeout)
98
- 2. Add ability to run different health monitors at different times or
99
- possibly call monitors individually
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
 
@@ -1,6 +1,6 @@
1
1
  module SystemHealth
2
2
  class Monitor
3
- def initialize(monitor_classes)
3
+ def initialize(monitor_classes = SystemHealth.configuration.monitor_classes)
4
4
  @monitor_classes = monitor_classes
5
5
  end
6
6
 
@@ -0,0 +1,17 @@
1
+ module SystemHealth
2
+ module Monitors
3
+ class Sql < Base
4
+
5
+ private
6
+
7
+ def bad_data?
8
+ ActiveRecord::Base.connection.execute(sql).count > 0
9
+ end
10
+
11
+ def sql
12
+ raise
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -1,3 +1,3 @@
1
1
  module SystemHealth
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -7,8 +7,14 @@ module SystemHealth
7
7
 
8
8
  context 'when errors' do
9
9
  class MonitorDouble < Monitors::Base
10
- def add_error_messages
11
- add_error_message('hello')
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 add_error_messages
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.5
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-28 00:00:00.000000000 Z
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