cepa-health 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cepa-health.rb +7 -8
- data/lib/cepa-health/version.rb +1 -1
- data/probes/delayed_job.rb +15 -10
- data/probes/mongoid.rb +3 -2
- data/probes/rails.rb +2 -3
- data/probes/sqlite.rb +2 -3
- metadata +1 -1
data/lib/cepa-health.rb
CHANGED
@@ -8,10 +8,9 @@ module CepaHealth
|
|
8
8
|
class Result
|
9
9
|
attr_reader :records
|
10
10
|
|
11
|
-
def execute(
|
12
|
-
v =
|
13
|
-
|
14
|
-
record(name, v, v ? "Success" : "Failed")
|
11
|
+
def execute(block)
|
12
|
+
v = instance_exec(&block)
|
13
|
+
Array === v ? record(*v) : record("Probe", v, v ? "Success" : "Failed")
|
15
14
|
end
|
16
15
|
|
17
16
|
def initialize
|
@@ -21,7 +20,7 @@ module CepaHealth
|
|
21
20
|
|
22
21
|
def record(name, status, comment)
|
23
22
|
@success = @success && !!status
|
24
|
-
@records << [name, status, comment]
|
23
|
+
@records << [name.to_s, !!status, comment.to_s]
|
25
24
|
end
|
26
25
|
|
27
26
|
def success?
|
@@ -45,7 +44,7 @@ module CepaHealth
|
|
45
44
|
result = CepaHealth::Result.new
|
46
45
|
filters = filters.map { |v| v.to_s }
|
47
46
|
selected = filters.empty? ? probes : probes.select { |k,v| filters.include?(k) }
|
48
|
-
selected.values.flatten(1).each { |v| result.execute(
|
47
|
+
selected.values.flatten(1).each { |v| result.execute(v) }
|
49
48
|
result
|
50
49
|
end
|
51
50
|
|
@@ -63,9 +62,9 @@ module CepaHealth
|
|
63
62
|
|
64
63
|
# Registers the given block as a probe. An optional level can be supplied,
|
65
64
|
# which can be used as a filter.
|
66
|
-
def register(
|
65
|
+
def register(level = :error, &block)
|
67
66
|
list = probes[level.to_s] ||= []
|
68
|
-
list <<
|
67
|
+
list << block
|
69
68
|
self
|
70
69
|
end
|
71
70
|
|
data/lib/cepa-health/version.rb
CHANGED
data/probes/delayed_job.rb
CHANGED
@@ -3,21 +3,20 @@
|
|
3
3
|
|
4
4
|
if defined?(Delayed)
|
5
5
|
|
6
|
-
CepaHealth.register
|
6
|
+
CepaHealth.register :warn do
|
7
7
|
now = Time.now.utc
|
8
8
|
record "Delayed Job Backlog", true, Delayed::Job.count
|
9
9
|
|
10
10
|
# Detect if the DJ backend is ActiveRecord or Mongoid Based
|
11
|
-
|
12
|
-
when Delayed::Job.respond_to?(:order_by) then
|
13
|
-
when Delayed::Job.respond_to?(:order) then
|
11
|
+
type = case
|
12
|
+
when Delayed::Job.respond_to?(:order_by) then :mongoid
|
13
|
+
when Delayed::Job.respond_to?(:order) then :active_record
|
14
14
|
else nil
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# Maximum Delayed Job age is 10 minutes
|
17
|
+
# Maximum Delayed Job age is 10 minutes
|
18
|
+
unless type.nil?
|
19
|
+
query = type == :active_record ? Delayed::Job.order("run_at DESC") : Delayed::Job.order_by(:run_at.desc)
|
21
20
|
value = query.last
|
22
21
|
if value.nil? || value.run_at > now
|
23
22
|
record 'Delayed Job Backlog Age', true, 'No expired jobs'
|
@@ -27,7 +26,13 @@ if defined?(Delayed)
|
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
# Check for failed jobs
|
30
|
+
if type.nil?
|
31
|
+
[ "Unknown Delayed Job Backend", false, "#{Delayed::Job}" ]
|
32
|
+
else
|
33
|
+
failures = type == :active_record ? Delayed::Job.where('attempts > 0').count : Delayed::Job.where(:attempts.gt => 0).count
|
34
|
+
["Delayed Job Failures", failures == 0, "#{failures} failed job#{failures == 1 ? '' : 's'}"]
|
35
|
+
end
|
36
|
+
end
|
32
37
|
|
33
38
|
end
|
data/probes/mongoid.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
if defined?(Mongoid)
|
5
5
|
|
6
|
-
CepaHealth.register
|
6
|
+
CepaHealth.register do
|
7
7
|
value = { 'ok' => nil }
|
8
8
|
tries = 3
|
9
9
|
begin
|
@@ -13,7 +13,8 @@ if defined?(Mongoid)
|
|
13
13
|
tries -= 1
|
14
14
|
retry unless tries <= 0
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
|
+
[ "Mongoid", value['ok'] == 1.0, "Ping Database"]
|
17
18
|
end
|
18
19
|
|
19
20
|
end
|
data/probes/rails.rb
CHANGED
@@ -4,9 +4,8 @@
|
|
4
4
|
if defined?(Rails)
|
5
5
|
|
6
6
|
# A Trivial Rails probe.
|
7
|
-
CepaHealth.register
|
8
|
-
|
9
|
-
true
|
7
|
+
CepaHealth.register do
|
8
|
+
["Rails Major Version", true, Rails.version.split('.').first]
|
10
9
|
end
|
11
10
|
|
12
11
|
end
|
data/probes/sqlite.rb
CHANGED
@@ -6,10 +6,9 @@ if defined?(ActiveRecord) && defined?(SQLite3)
|
|
6
6
|
CepaHealth.register "SQLite" do
|
7
7
|
begin
|
8
8
|
ActiveRecord::Base.connection.exec_query("PRAGMA quick_check")
|
9
|
-
true
|
9
|
+
[ "SQLite", true, "Quick Check" ]
|
10
10
|
rescue Exception => e
|
11
|
-
|
12
|
-
false
|
11
|
+
[ "SQLite", false, e.inspect ]
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|