Class: OkComputer::CacheCheck
- Defined in:
- lib/ok_computer/built_in_checks/cache_check.rb
Overview
Verifies that the Rails cache is set up and can speak with Memcached running on the given host (defaults to local).
Constant Summary
Constants inherited from Check
OkComputer::Check::CheckNotDefined
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
Attributes inherited from Check
#failure_occurred, #message, #registrant_name, #time
Instance Method Summary collapse
-
#check ⇒ Object
Public: Check whether the cache is active.
-
#initialize(host = Socket.gethostname) ⇒ CacheCheck
constructor
A new instance of CacheCheck.
-
#stats ⇒ Object
Public: Outputs stats string for cache.
Methods inherited from Check
#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking
Constructor Details
#initialize(host = Socket.gethostname) ⇒ CacheCheck
Returns a new instance of CacheCheck.
7 8 9 |
# File 'lib/ok_computer/built_in_checks/cache_check.rb', line 7 def initialize(host=Socket.gethostname) self.host = host end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/ok_computer/built_in_checks/cache_check.rb', line 5 def host @host end |
Instance Method Details
#check ⇒ Object
Public: Check whether the cache is active
12 13 14 15 16 17 |
# File 'lib/ok_computer/built_in_checks/cache_check.rb', line 12 def check "Cache is available (#{stats})" rescue ConnectionFailed => e mark_failure "Error: '#{e}'" end |
#stats ⇒ Object
Public: Outputs stats string for cache
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ok_computer/built_in_checks/cache_check.rb', line 20 def stats return "" unless Rails.cache.respond_to? :stats stats = Rails.cache.stats values = stats.select{|k,v| k =~ Regexp.new(host) }.values[0] mem_used = to_megabytes values['bytes'] mem_max = to_megabytes values['limit_maxbytes'] return "#{mem_used} / #{mem_max} MB, #{stats.count - 1} peers" rescue => e raise ConnectionFailed, e end |