]> git.pld-linux.org Git - packages/cacti-template-varnish.git/blame - get_varnish_stats.py
- pull more data for new template
[packages/cacti-template-varnish.git] / get_varnish_stats.py
CommitLineData
69382e8f 1#!/usr/bin/python
088278ef
ER
2# $Id$
3# Author: Elan Ruusamäe <glen@delfi.ee>
4#
5# Original varnish stat script by dmuntean from http://forums.cacti.net/viewtopic.php?t=31260
6# Modified by glen to add support for new template: http://forums.cacti.net/viewtopic.php?p=182152
7#
8
69382e8f
ER
9import telnetlib
10import re
11import sys
12import getopt
13
14opts, args = getopt.getopt(sys.argv[1:], "h:p:", ["host=", "port="])
15host = '127.0.0.1'
088278ef 16port = 6082
69382e8f
ER
17for o, v in opts:
18 if o in ("-h", "--host"):
19 host = str(v)
20 if o in ("-p", "--port"):
21 port = int(v)
22
23telnet = telnetlib.Telnet()
24telnet.open(host, port)
25telnet.write('stats\r\n')
088278ef 26out = telnet.read_until("ESI parse errors (unlock)", 10)
69382e8f
ER
27telnet.write('quit\r\n')
28telnet.close()
29
088278ef
ER
30# This serves as template for matching keys.
31# Also all entries present in this table must be present in result
32# You should upgrade Varnish 2.1 as Varnish 2.0 does not have "uptime" column.
33sample = """
34uptime 17903 . Child uptime
35client_conn 3333449 186.19 Client connections accepted
36client_req 14776402 825.36 Client requests received
37cache_hit 13929762 778.07 Cache hits
38cache_hitpass 52996 2.96 Cache hits for pass
39cache_miss 788513 44.04 Cache misses
40backend_conn 494618 27.63 Backend conn. success
41backend_unhealthy 0 0.00 Backend conn. not attempted
42backend_busy 0 0.00 Backend conn. too many
43backend_fail 0 0.00 Backend conn. failures
44backend_reuse 351664 19.64 Backend conn. reuses
45backend_recycle 817584 45.67 Backend conn. recycles
46backend_unused 0 0.00 Backend conn. unused
47n_srcaddr 0 . N struct srcaddr
48n_srcaddr_act 0 . N active struct srcaddr
49n_sess_mem 2200 . N struct sess_mem
50n_sess 1207 . N struct sess
51n_object 151202 . N struct object
52n_objecthead 91698 . N struct objecthead
53n_smf 326799 . N struct smf
54n_smf_frag 24687 . N small free smf
55n_smf_large 326 . N large free smf
56n_vbe_conn 26 . N struct vbe_conn
57n_bereq 212 . N struct bereq
58n_wrk 600 . N worker threads
59n_wrk_create 600 0.03 N worker threads created
60n_wrk_failed 0 0.00 N worker threads not created
61n_wrk_max 0 0.00 N worker threads limited
62n_wrk_queue 0 0.00 N queued work requests
63n_wrk_overflow 2639 0.15 N overflowed work requests
64n_wrk_drop 0 0.00 N dropped work requests
65n_backend 20 . N backends
66n_expired 472014 . N expired objects
67n_lru_nuked 165622 . N LRU nuked objects
68n_lru_saved 0 . N LRU saved objects
69n_lru_moved 6575346 . N LRU moved objects
70n_objsendfile 0 0.00 Objects sent with sendfile
71n_objwrite 14087414 786.87 Objects sent with write
72n_objoverflow 0 0.00 Objects overflowing workspace
73s_pipe 879 0.05 Total pipe
74s_pass 56935 3.18 Total pass
75s_hdrbytes 5095096301 284594.55 Total header bytes
76s_bodybytes 105139468938 5872729.09 Total body bytes
77sess_closed 211106 11.79 Session Closed
78sess_pipeline 52085 2.91 Session Pipeline
79sess_readahead 54758 3.06 Session Read Ahead
80sess_linger 14576708 814.20 Session Linger
81sess_herd 11874652 663.28 Session herd
82shm_records 626744114 35007.77 SHM records
83shm_writes 37710636 2106.39 SHM writes
84shm_flushes 32226 1.80 SHM flushes due to overflow
85shm_cont 101165 5.65 SHM MTX contention
86shm_cycles 256 0.01 SHM cycles through buffer
87sm_nreq 1857435 103.75 allocator requests
88sm_balloc 3918831616 . bytes allocated
89sma_nreq 0 0.00 SMA allocator requests
90sma_nbytes 0 . SMA outstanding bytes
91sms_nreq 344 0.02 SMS allocator requests
92sms_nbytes 0 . SMS outstanding bytes
93backend_req 845376 47.22 Backend requests made
94n_vcl 1 0.00 N vcl total
95n_vcl_avail 1 0.00 N vcl available
96n_vcl_discard 0 0.00 N vcl discarded
97n_purge 1 . N total active purges
98n_purge_add 1 0.00 N new purges added
99n_purge_retire 0 0.00 N old purges deleted
100n_purge_obj_test 0 0.00 N objects tested
101n_purge_re_test 0 0.00 N regexps tested against
102n_purge_dups 0 0.00 N duplicate purges removed
103hcb_nolock 0 0.00 HCB Lookups without lock
104hcb_lock 0 0.00 HCB Lookups with lock
105hcb_insert 0 0.00 HCB Inserts
106esi_parse 0 0.00 Objects ESI parsed (unlock)
107esi_errors 0 0.00 ESI parse errors (unlock)
108"""
69382e8f 109
088278ef
ER
110# process results
111split = re.compile('^\s*(?P<value>\S+)\s+(?P<key>.+)$')
112res = {}
113for line in out.split('\n'):
114 m = re.search(split, line);
115 if m:
116 res[m.group('key')] = m.group('value')
69382e8f 117
088278ef
ER
118# map for keys
119split = re.compile('^(?P<key>\S+)\s+(\d+)\s+\S+\s+(?P<value>.+)$')
120for line in sample.split('\n'):
121 m = re.search(split, line);
122 if m:
123 if res.has_key(m.group('value')):
124 value = res[m.group('value')]
125 print "%s:%s" % (m.group('key'), value),
126 else:
127 # for missing value, print -1
128 print "%s:-1" % m.group('key'),
69382e8f 129
088278ef
ER
130# print results for original script
131req = res['Client requests received']
132hit = float(res['Cache hits'])
133miss = float(res['Cache misses'])
69382e8f 134print 'varnish_requests:'+str(req)+' varnish_hitrate:'+str(round(hit / (hit + miss) * 100, 1))
This page took 0.101196 seconds and 4 git commands to generate.