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