-
Notifications
You must be signed in to change notification settings - Fork 4
/
Memcached.py
66 lines (52 loc) · 2.18 KB
/
Memcached.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import getopt
import telnetlib
import re
import socket
class Memcached:
def __init__(self, agentConfig, checksLogger, rawConfig):
self.agentConfig = agentConfig
self.checksLogger = checksLogger
self.rawConfig = rawConfig
def run(self):
stats = {}
host = "127.0.0.1"
port = 11211
try:
telnet = telnetlib.Telnet()
telnet.open(host, port)
telnet.write('stats\r\n')
out = telnet.read_until("END")
telnet.write('quit\r\n')
telnet.close()
except socket.error, reason:
sys.stderr.write("%s\n" % reason)
sys.stderr.write("Is memcached running?\n")
return stats
# Current / Total
stats['curr_items'] = int(re.search("curr_items (\d+)", out).group(1))
stats['total_items'] = int(re.search("total_items (\d+)", out).group(1))
# Memory Usgae
stats['limit_maxbytes'] = int(re.search("limit_maxbytes (\d+)", out).group(1))
stats['bytes'] = int(re.search("bytes (\d+)", out).group(1))
# Network Traffic
stats['bytes_read'] = int(re.search("bytes_read (\d+)", out).group(1))
stats['bytes_written'] = int(re.search("bytes_written (\d+)", out).group(1))
# Connections
stats['curr_connections'] = int(re.search("curr_connections (\d+)", out).group(1))
stats['total_connections'] = int(re.search("total_connections (\d+)", out).group(1))
# Hits / Misses
stats['cmd_get'] = int(re.search("cmd_get (\d+)", out).group(1))
stats['cmd_set'] = int(re.search("cmd_set (\d+)", out).group(1))
stats['get_hits'] = int(re.search("get_hits (\d+)", out).group(1))
stats['get_misses'] = int(re.search("get_misses (\d+)", out).group(1))
stats['delete_hits'] = int(re.search("delete_hits (\d+)", out).group(1))
stats['delete_misses'] = int(re.search("delete_misses (\d+)", out).group(1))
stats['incr_hits'] = int(re.search("incr_hits (\d+)", out).group(1))
stats['decr_hits'] = int(re.search("decr_hits (\d+)", out).group(1))
stats['incr_misses'] = int(re.search("incr_misses (\d+)", out).group(1))
stats['decr_misses'] = int(re.search("decr_misses (\d+)", out).group(1))
# Evictions
stats['evictions'] = int(re.search("evictions (\d+)", out).group(1))
stats['reclaimed'] = int(re.search("reclaimed (\d+)", out).group(1))
return stats