summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--memcache.py42
1 files changed, 39 insertions, 3 deletions
diff --git a/memcache.py b/memcache.py
index 2f1d323..f0dccd8 100644
--- a/memcache.py
+++ b/memcache.py
@@ -49,7 +49,6 @@ from __future__ import print_function
import binascii
import os
-import pickle
import re
import socket
import sys
@@ -59,6 +58,12 @@ import zlib
import six
+if six.PY2:
+ # With Python 2, the faster C implementation has to be imported explicitly.
+ import cPickle as pickle
+else:
+ import pickle
+
def cmemcache_hash(key):
return (
@@ -333,13 +338,44 @@ class Client(threading.local):
readline = s.readline
while 1:
line = readline()
- if not line or line.strip() == 'END':
+ if not line or line.decode('ascii').strip() == 'END':
break
- stats = line.split(' ', 2)
+ stats = line.decode('ascii').split(' ', 2)
serverData[stats[1]] = stats[2]
return(data)
+ def get_slab_stats(self):
+ data = []
+ for s in self.servers:
+ if not s.connect():
+ continue
+ if s.family == socket.AF_INET:
+ name = '%s:%s (%s)' % (s.ip, s.port, s.weight)
+ elif s.family == socket.AF_INET6:
+ name = '[%s]:%s (%s)' % (s.ip, s.port, s.weight)
+ else:
+ name = 'unix:%s (%s)' % (s.address, s.weight)
+ serverData = {}
+ data.append((name, serverData))
+ s.send_cmd('stats slabs')
+ readline = s.readline
+ while 1:
+ line = readline()
+ if not line or line.strip() == 'END':
+ break
+ item = line.split(' ', 2)
+ if line.startswith('STAT active_slabs') or line.startswith('STAT total_malloced'):
+ serverData[item[1]]=item[2]
+ else:
+ # 0 = STAT, 1 = ITEM, 2 = Value
+ slab = item[1].split(':', 2)
+ # 0 = Slab #, 1 = Name
+ if slab[0] not in serverData:
+ serverData[slab[0]] = {}
+ serverData[slab[0]][slab[1]] = item[2]
+ return data
+
def get_slabs(self):
data = []
for s in self.servers: