Class: IsItWorking::DalliCheck
- Inherits:
-
Object
- Object
- IsItWorking::DalliCheck
- Defined in:
- lib/is_it_working/checks/dalli_check.rb
Instance Method Summary collapse
- #call(status) ⇒ Object
-
#initialize(options = {}) ⇒ DalliCheck
constructor
Check if all the memcached servers in a cluster are responding.
Constructor Details
#initialize(options = {}) ⇒ DalliCheck
Check if all the memcached servers in a cluster are responding. The memcache cluster to check is specified with the :cache
options. The value can be either a Dalli::Client object (from the dalli gem) or an ActiveSupport::Cache::DalliStore (i.e. Rails.cache).
If making the IP addresses of the memcache servers known to the world could pose a security risk because they are not on a private network behind a firewall, you can provide the :alias
option to change the host names that are reported.
Example
IsItWorking::Handler.new do |h|
h.check :dalli, :cache => Rails.cache, :alias => "memcache server"
end
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/is_it_working/checks/dalli_check.rb', line 19 def initialize(={}) memcache = [:cache] raise ArgumentError.new(":cache not specified") unless memcache unless memcache.is_a?(Dalli::Client) if defined?(ActiveSupport::Cache::DalliStore) && memcache.is_a?(ActiveSupport::Cache::DalliStore) # Big hack to get the MemCache object from Rails.cache @memcache = memcache.instance_variable_get(:@data) else raise ArgumentError.new("#{memcache} is not a Dalli::Client") end else @memcache = memcache end @alias = [:alias] end |
Instance Method Details
#call(status) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/is_it_working/checks/dalli_check.rb', line 35 def call(status) servers = @memcache.send(:ring).servers servers.each_with_index do |server, i| public_host_name = @alias ? "#{@alias} #{i + 1}" : "#{server.hostname}:#{server.port}" if server.alive? status.ok("#{public_host_name} is available") else status.fail("#{public_host_name} is not available") end end end |