Module: Kestrel::Client::StatsHelper

Included in:
Kestrel::Client
Defined in:
lib/kestrel/client/stats_helper.rb

Constant Summary collapse

STATS_TIMEOUT =
3
QUEUE_STAT_NAMES =
%w{items bytes total_items logsize expired_items mem_items mem_bytes age discarded waiters open_transactions}

Instance Method Summary collapse

Instance Method Details

#available_queuesObject



10
11
12
# File 'lib/kestrel/client/stats_helper.rb', line 10

def available_queues
  stats['queues'].keys.sort
end

#sizeof(queue) ⇒ Object



5
6
7
8
# File 'lib/kestrel/client/stats_helper.rb', line 5

def sizeof(queue)
  stat_info = stat(queue)
  stat_info ? stat_info['items'] : 0
end

#stat(queue) ⇒ Object



34
35
36
# File 'lib/kestrel/client/stats_helper.rb', line 34

def stat(queue)
  stats['queues'][queue]
end

#statsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kestrel/client/stats_helper.rb', line 14

def stats
  alive, dead = 0, 0

  results = servers.map do |server|
    begin
      result = stats_for_server(server)
      alive += 1
      result
    rescue Exception
      dead += 1
      nil
    end
  end.compact

  stats = merge_stats(results)
  stats['alive_servers'] = alive
  stats['dead_servers']  = dead
  stats
end