Skip to content

Commit

Permalink
Merge pull request petergoldstein#337 from bukhamseen/detailed-stats
Browse files Browse the repository at this point in the history
Support detailed stats.
  • Loading branch information
mperham committed Mar 11, 2013
2 parents 7f49b30 + d298fe7 commit c0a9b28
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Dalli Changelog

HEAD
=======

- Support specific stats by passing `:items` or `:slabs` to `stats` method [bukhamseen]
- Fix 'can't modify frozen String' errors in `ActiveSupport::Cache::DalliStore` [dblock]

2.6.2
Expand Down
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
18 changes: 17 additions & 1 deletion test/test_dalli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,23 @@
servers = stats.keys
assert(servers.any? do |s|
stats[s]["get_hits"].to_i != 0
end)
end, "general stats failed")

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

stats_slabs = dc.stats(:slabs)
servers = stats_slabs.keys
assert(servers.all? do |s|
stats_slabs[s].keys.any? do |key|
key == "active_slabs"
end
end, "stats slabs failed")

# reset_stats test
results = dc.reset_stats
Expand Down

0 comments on commit c0a9b28

Please sign in to comment.