2 # vim: set encoding=utf-8:
4 # Author: Elan Ruusamäe <glen@delfi.ee>
6 # Original varnish stat script by dmuntean from http://forums.cacti.net/viewtopic.php?t=31260
7 # Modified by glen to add support for new template: http://forums.cacti.net/viewtopic.php?p=182152
15 opts, args = getopt.getopt(sys.argv[1:], "h:p:", ["host=", "port="])
19 if o in ("-h", "--host"):
21 if o in ("-p", "--port"):
24 telnet = telnetlib.Telnet()
25 telnet.open(host, port)
26 telnet.write('stats\r\n')
27 out = telnet.read_until("ESI parse errors (unlock)", 10)
28 telnet.write('quit\r\n')
31 # This serves as template for matching keys.
32 # Also all entries present in this table must be present in result
33 # You should upgrade Varnish 2.1 as Varnish 2.0 does not have "uptime" column.
35 uptime 36897 . Child uptime
36 client_conn 6724115 182.24 Client connections accepted
37 client_drop 0 0.00 Connection dropped, no sess
38 client_req 29357678 795.67 Client requests received
39 cache_hit 27645207 749.25 Cache hits
40 cache_hitpass 114269 3.10 Cache hits for pass
41 cache_miss 1586933 43.01 Cache misses
42 backend_conn 995606 26.98 Backend conn. success
43 backend_unhealthy 0 0.00 Backend conn. not attempted
44 backend_busy 0 0.00 Backend conn. too many
45 backend_fail 1 0.00 Backend conn. failures
46 backend_reuse 716090 19.41 Backend conn. reuses
47 backend_toolate 937223 25.40 Backend conn. was closed
48 backend_recycle 1653334 44.81 Backend conn. recycles
49 backend_unused 0 0.00 Backend conn. unused
50 fetch_head 33 0.00 Fetch head
51 fetch_length 613801 16.64 Fetch with Length
52 fetch_chunked 1087578 29.48 Fetch chunked
53 fetch_eof 0 0.00 Fetch EOF
54 fetch_bad 0 0.00 Fetch had bad headers
55 fetch_close 5649 0.15 Fetch wanted close
56 fetch_oldhttp 0 0.00 Fetch pre HTTP/1.1 closed
57 fetch_zero 2304 0.06 Fetch zero len
58 fetch_failed 17 0.00 Fetch failed
59 n_srcaddr 0 . N struct srcaddr
60 n_srcaddr_act 0 . N active struct srcaddr
61 n_sess_mem 2200 . N struct sess_mem
62 n_sess 1168 . N struct sess
63 n_object 76813 . N struct object
64 n_objecthead 51153 . N struct objecthead
65 n_smf 159665 . N struct smf
66 n_smf_frag 4500 . N small free smf
67 n_smf_large 1979 . N large free smf
68 n_vbe_conn 29 . N struct vbe_conn
69 n_bereq 212 . N struct bereq
70 n_wrk 600 . N worker threads
71 n_wrk_create 600 0.02 N worker threads created
72 n_wrk_failed 0 0.00 N worker threads not created
73 n_wrk_max 0 0.00 N worker threads limited
74 n_wrk_queue 0 0.00 N queued work requests
75 n_wrk_overflow 2639 0.07 N overflowed work requests
76 n_wrk_drop 0 0.00 N dropped work requests
77 n_backend 20 . N backends
78 n_expired 808579 . N expired objects
79 n_lru_nuked 701957 . N LRU nuked objects
80 n_lru_saved 0 . N LRU saved objects
81 n_lru_moved 13197669 . N LRU moved objects
82 n_deathrow 0 . N objects on deathrow
83 losthdr 10 0.00 HTTP header overflows
84 n_objsendfile 0 0.00 Objects sent with sendfile
85 n_objwrite 27988657 758.56 Objects sent with write
86 n_objoverflow 0 0.00 Objects overflowing workspace
87 s_sess 6724087 182.24 Total Sessions
88 s_req 29358671 795.69 Total Requests
89 s_pipe 2219 0.06 Total pipe
90 s_pass 122593 3.32 Total pass
91 s_fetch 1709352 46.33 Total fetch
92 s_hdrbytes 10134822172 274678.76 Total header bytes
93 s_bodybytes 210452858412 5703793.22 Total body bytes
94 sess_closed 404260 10.96 Session Closed
95 sess_pipeline 110465 2.99 Session Pipeline
96 sess_readahead 117895 3.20 Session Read Ahead
97 sess_linger 28952376 784.68 Session Linger
98 sess_herd 23901613 647.79 Session herd
99 shm_records 1248208604 33829.54 SHM records
100 shm_writes 75556170 2047.76 SHM writes
101 shm_flushes 54950 1.49 SHM flushes due to overflow
102 shm_cont 238017 6.45 SHM MTX contention
103 shm_cycles 509 0.01 SHM cycles through buffer
104 sm_nreq 4123515 111.76 allocator requests
105 sm_nobj 153186 . outstanding allocations
106 sm_balloc 2119176192 . bytes allocated
107 sm_bfree 4323274752 . bytes free
108 sma_nreq 0 0.00 SMA allocator requests
109 sma_nobj 0 . SMA outstanding allocations
110 sma_nbytes 0 . SMA outstanding bytes
111 sma_balloc 0 . SMA bytes allocated
112 sma_bfree 0 . SMA bytes free
113 sms_nreq 617 0.02 SMS allocator requests
114 sms_nobj 0 . SMS outstanding allocations
115 sms_nbytes 0 . SMS outstanding bytes
116 sms_balloc 4539572 . SMS bytes allocated
117 sms_bfree 4539572 . SMS bytes freed
118 backend_req 1709428 46.33 Backend requests made
119 n_vcl 1 0.00 N vcl total
120 n_vcl_avail 1 0.00 N vcl available
121 n_vcl_discard 0 0.00 N vcl discarded
122 n_purge 1 . N total active purges
123 n_purge_add 1 0.00 N new purges added
124 n_purge_retire 0 0.00 N old purges deleted
125 n_purge_obj_test 0 0.00 N objects tested
126 n_purge_re_test 0 0.00 N regexps tested against
127 n_purge_dups 0 0.00 N duplicate purges removed
128 hcb_nolock 0 0.00 HCB Lookups without lock
129 hcb_lock 0 0.00 HCB Lookups with lock
130 hcb_insert 0 0.00 HCB Inserts
131 esi_parse 0 0.00 Objects ESI parsed (unlock)
132 esi_errors 0 0.00 ESI parse errors (unlock)
136 split = re.compile('^\s*(?P<value>\S+)\s+(?P<key>.+)$')
138 for line in out.split('\n'):
139 m = re.search(split, line);
141 res[m.group('key')] = m.group('value')
144 split = re.compile('^(?P<key>\S+)\s+(\d+)\s+\S+\s+(?P<value>.+)$')
145 for line in sample.split('\n'):
146 m = re.search(split, line);
148 if res.has_key(m.group('value')):
149 value = res[m.group('value')]
150 print "%s:%s" % (m.group('key'), value),
152 # for missing value, print -1
153 print "%s:-1" % m.group('key'),
155 # print results for original script
156 req = res['Client requests received']
157 hit = float(res['Cache hits'])
158 miss = float(res['Cache misses'])
159 print 'varnish_requests:'+str(req)+' varnish_hitrate:'+str(round(hit / (hit + miss) * 100, 1))