]> git.pld-linux.org Git - packages/cacti-template-varnish.git/commitdiff
- from http://forums.cacti.net/viewtopic.php?t=31260
authorElan Ruusamäe <glen@pld-linux.org>
Tue, 13 Apr 2010 12:14:30 +0000 (12:14 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
  varnish-cacti-stats-0.0.2.zip archive

Changed files:
    get_varnish_stats.py -> 1.1

get_varnish_stats.py [new file with mode: 0644]

diff --git a/get_varnish_stats.py b/get_varnish_stats.py
new file mode 100644 (file)
index 0000000..e7633a6
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/python
+import telnetlib
+import re
+import sys
+import getopt
+
+opts, args = getopt.getopt(sys.argv[1:], "h:p:", ["host=", "port="])
+host = '127.0.0.1'
+port = 9001
+for o, v in opts:
+    if o in ("-h", "--host"):
+        host = str(v)
+    if o in ("-p", "--port"):
+        port = int(v)
+       
+telnet = telnetlib.Telnet()
+telnet.open(host, port)
+telnet.write('stats\r\n')
+out=telnet.read_until("N duplicate purges removed", 10)
+telnet.write('quit\r\n')
+telnet.close()
+
+req = re.search("\d+  Client requests received", out)
+req = req.group(0).split()[0]
+
+hit = re.search("\d+  Cache hits", out)
+hit = float(hit.group(0).split()[0])
+
+miss = re.search("\d+  Cache misses", out)
+miss = float(miss.group(0).split()[0])
+
+print 'varnish_requests:'+str(req)+' varnish_hitrate:'+str(round(hit / (hit + miss) * 100, 1))
+
This page took 0.118016 seconds and 4 git commands to generate.