Skip to content

Commit

Permalink
Adding memcached.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelclay committed Feb 5, 2010
1 parent ed2f769 commit 73bc362
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions utils/memcached_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import memcache
import re
import sys
from settings import CACHE_BACKEND
#gfranxman

verbose = False

if not CACHE_BACKEND.startswith( 'memcached://' ):
print "you are not configured to use memcched as your django cache backend"
else:
m = re.search( r'//(.+:\d+)', CACHE_BACKEND )
cache_host = m.group(1)

h = memcache._Host( cache_host )
h.connect()
h.send_cmd( 'stats' )

stats = {}

pat = re.compile( r'STAT (\w+) (\w+)' )

l = '' ;
while l.find( 'END' ) < 0 :
l = h.readline()
if verbose:
print l
m = pat.match( l )
if m :
stats[ m.group(1) ] = m.group(2)


h.close_socket()

if verbose:
print stats

items = int( stats[ 'curr_items' ] )
bytes = int( stats[ 'bytes' ] )
limit_maxbytes = int( stats[ 'limit_maxbytes' ] ) or bytes
current_conns = int( stats[ 'curr_connections' ] )

print "MemCache status for %s" % ( CACHE_BACKEND )
print "%d items using %d of %d" % ( items, bytes, limit_maxbytes )
print "%5.2f%% full" % ( 100.0 * bytes / limit_maxbytes )
print "%d connections being handled" % ( current_conns )
print

0 comments on commit 73bc362

Please sign in to comment.