]>
Commit | Line | Data |
---|---|---|
69382e8f ER |
1 | #!/usr/bin/python |
2 | import telnetlib | |
3 | import re | |
4 | import sys | |
5 | import getopt | |
6 | ||
7 | opts, args = getopt.getopt(sys.argv[1:], "h:p:", ["host=", "port="]) | |
8 | host = '127.0.0.1' | |
9 | port = 9001 | |
10 | for o, v in opts: | |
11 | if o in ("-h", "--host"): | |
12 | host = str(v) | |
13 | if o in ("-p", "--port"): | |
14 | port = int(v) | |
15 | ||
16 | telnet = telnetlib.Telnet() | |
17 | telnet.open(host, port) | |
18 | telnet.write('stats\r\n') | |
19 | out=telnet.read_until("N duplicate purges removed", 10) | |
20 | telnet.write('quit\r\n') | |
21 | telnet.close() | |
22 | ||
23 | req = re.search("\d+ Client requests received", out) | |
24 | req = req.group(0).split()[0] | |
25 | ||
26 | hit = re.search("\d+ Cache hits", out) | |
27 | hit = float(hit.group(0).split()[0]) | |
28 | ||
29 | miss = re.search("\d+ Cache misses", out) | |
30 | miss = float(miss.group(0).split()[0]) | |
31 | ||
32 | print 'varnish_requests:'+str(req)+' varnish_hitrate:'+str(round(hit / (hit + miss) * 100, 1)) | |
33 |