Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 80de745577
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (31 sloc) 1.123 kb
import socket
from porkchop.plugin import PorkchopPlugin
class MemcachedPlugin(PorkchopPlugin):
def _connect(self, host, port):
try:
sock = socket.socket()
sock.connect((host, port))
except:
raise
return sock
def get_data(self):
data = self.gendict()
instance_config = self.config.get('memcached', {}).get('instances',
'localhost:11211')
instances = [s.strip().split(':') for s in instance_config.split(',')]
for host, port in instances:
resp_data = ''
try:
sock = self._connect(host, int(port))
sock.send('stats\r\nquit\r\n')
while not resp_data.endswith('END\r\n'):
resp_data += sock.recv(1024)
sock.close()
except socket.error:
continue
for line in resp_data.splitlines():
if not line.startswith('STAT'):
continue
trash, k, v = line.split()
data[port][k] = v
return data
Jump to Line
Something went wrong with that request. Please try again.