Class: Healthy::Diagnostic
- Inherits:
-
Object
- Object
- Healthy::Diagnostic
- Defined in:
- lib/healthy/base.rb,
lib/healthy/diagnostic.rb
Defined Under Namespace
Modules: Base
Class Method Summary collapse
- .all_good? ⇒ Boolean
- .checks ⇒ Object
- .diagnostics ⇒ Object
- .extract_name(obj) ⇒ Object
- .flush_diagnostics! ⇒ Object
- .info_for(normalized_name) ⇒ Object
- .monitor(diagnostic) ⇒ Object
- .site_host ⇒ Object
- .site_host=(value) ⇒ Object
- .status ⇒ Object
- .tools ⇒ Object
Class Method Details
.all_good? ⇒ Boolean
27 28 29 |
# File 'lib/healthy/diagnostic.rb', line 27 def all_good? status == :pass end |
.checks ⇒ Object
56 57 58 |
# File 'lib/healthy/diagnostic.rb', line 56 def checks diagnostics.select{|diagnostic| diagnostic.respond_to?(:passed?) }.sort{|x,y| extract_name(x) <=> extract_name(y)} end |
.diagnostics ⇒ Object
47 48 49 |
# File 'lib/healthy/diagnostic.rb', line 47 def diagnostics @diagnostics.uniq.collect(&:new) end |
.extract_name(obj) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/healthy/diagnostic.rb', line 64 def extract_name(obj) if obj.respond_to?(:name) obj.name else obj.class.name end end |
.flush_diagnostics! ⇒ Object
51 52 53 54 |
# File 'lib/healthy/diagnostic.rb', line 51 def flush_diagnostics! @diagnostics.uniq.clear Router.routes = nil end |
.info_for(normalized_name) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/healthy/diagnostic.rb', line 4 def info_for(normalized_name) route = Router.routes[normalized_name] if ServerIdentity.matches?(route[:servers]) route[:klass].new.info else `curl -H 'Host: #{Diagnostic.site_host}' http://#{route[:servers].first}/status/#{normalized_name}` end end |
.monitor(diagnostic) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/healthy/diagnostic.rb', line 39 def monitor(diagnostic) @diagnostics ||= [] exsisting = @diagnostics.detect{|exsisting| exsisting.name == diagnostic.name } @diagnostics.delete(exsisting) if exsisting @diagnostics << diagnostic Router.add_route(diagnostic) end |
.site_host ⇒ Object
31 32 33 |
# File 'lib/healthy/diagnostic.rb', line 31 def site_host @@site_host end |
.site_host=(value) ⇒ Object
35 36 37 |
# File 'lib/healthy/diagnostic.rb', line 35 def site_host=(value) @@site_host=value end |
.status ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/healthy/diagnostic.rb', line 13 def status status = :pass checks.each do |check| case check.status when :warn status = warn when :fail return :fail end end status end |
.tools ⇒ Object
60 61 62 |
# File 'lib/healthy/diagnostic.rb', line 60 def tools diagnostics.select{|diagnostic| !diagnostic.respond_to?(:passed?) }.sort{|x,y| extract_name(x) <=> extract_name(y)} end |