Skip to content

Commit

Permalink
support detailed stats
Browse files Browse the repository at this point in the history
  • Loading branch information
hbu50 committed Mar 4, 2013
1 parent 5684a60 commit ecc364b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/dalli/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,13 @@ def touch(key, ttl=nil)

##
# Collect the stats for each server.
# You can optionaly pass a type including :items or :slabs to get specific stats
# Returns a hash like { 'hostname:port' => { 'stat1' => 'value1', ... }, 'hostname2:port' => { ... } }
def stats
def stats(type=nil)
type = nil if ![nil, :items,:slabs].include? type
values = {}
ring.servers.each do |server|
values["#{server.hostname}:#{server.port}"] = server.alive? ? server.request(:stats) : nil
values["#{server.hostname}:#{server.port}"] = server.alive? ? server.request(:stats,type.to_s) : nil
end
values
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_dalli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@
stats[s]["get_hits"].to_i != 0
end)

stats_items = dc.stats(:items)
servers = stats_items.keys
assert(servers.any? do |s|
stats_items[s].keys[0] =~ /items:[0-9]+:number/
end)

stats_slabs = dc.stats(:slabs)
servers = stats_slabs.keys
assert(servers.any? do |s|
stats_slabs[s].keys[0] =~ /[0-9]+:chunk_size/
end)

# reset_stats test
results = dc.reset_stats
assert(results.all? { |x| x })
Expand Down

0 comments on commit ecc364b

Please sign in to comment.