Ticket #7 (assigned enhancement)
Add access to more stats and a possibility to dump the cache
| Reported by: | darix@… | Owned by: | deveiant |
|---|---|---|---|
| Priority: | major | Milestone: | Add New Features |
| Component: | Source | Version: | 0.0.3 |
| Keywords: | additional statistics stats slabs | Cc: |
Description
as a proof of concept i wrote a small enhancement to the memcached class. it allows you to dump the content of the memcached. I did:
- add a function to read stats slabs
- get the keys of all items in each slab
- iterate over all slabs at get the item keys.
- query all items and return their values.
this really helps to debug.
my current code:
require 'rubygems'
require_gem 'Ruby-MemCache'
class MemCache
def cache_dump( servers=@servers )
asvrs = servers.select {|svr| svr.alive?}...
cmds = self.make_command_map( "stats slabs", asvrs )..
# Send them in parallel.
keys = Array.new
self.send( cmds ) do |svr,reply|
slab_stats = self.get_items_keys(self.parse_slab_reply(reply))
end
self.get_items(asvrs, keys)
end
def get_items (asvrs, keys)
values = Array.new
keys.each do | key |
cmds = self.make_command_map( "get #{key}", asvrs )
self.send( cmds ) do |svr,value|
values << value
end
end
return values
end
def get_items_keys (asvrs, slab_ids)
keys = Array.new
slab_ids.each do | slab_id |
kcmds = self.make_command_map( "stats cachedump #{slab_id} 0", asvrs )
self.send( kcmds ) do |svr,reply|
keys += self.parse_items_lines(reply)
end
end
return keys
end
def parse_items_lines (reply)
reply.map { | line | line.split(' ')[1] }
end
def parse_slab_reply (reply)
reply.map{|line| line[/(\d+):/, 1].to_i }.uniq
end
end
cache = MemCache::new '127.0.0.1:11211'
cache.debug = true
puts cache.cache_dump()
Change History
Note: See
TracTickets for help on using
tickets.

I'll look at adding this. If I can't get to it before the upcoming release, then I'll put it in a release of its own shortly thereafter.