forked from outlyerapp/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemcache.py
More file actions
executable file
·45 lines (36 loc) · 954 Bytes
/
memcache.py
File metadata and controls
executable file
·45 lines (36 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
import socket
import sys
HOST = 'localhost'
PORT = 11211
def query_stats():
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
client.connect((HOST, PORT))
client.send('stats\n')
resp = client.recv(1024)
client.close()
return resp
except:
print "Plugin Failed! Unable to connect to %s:%s" % (HOST, PORT)
sys.exit(2)
def process_response(r):
stats = {}
for line in r.split('\n'):
fields = line.split(' ')
if fields[0] == "STAT":
try:
stat = fields[2].replace('\r', '')
stats[fields[1]] = stat
except:
pass
return stats
def process_stats(s):
perf_data = "OK | "
for k in s:
perf_data += "%s=%s;;;; " % (k, s[k])
return perf_data
r = query_stats()
statistics = process_response(r)
print process_stats(statistics)
sys.exit(0)