]> git.pld-linux.org Git - packages/cacti-template-varnish.git/blame - get_varnish_stats.py
- some fields were missing
[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 = """
35uptime 17903 . Child uptime
36client_conn 3333449 186.19 Client connections accepted
37client_req 14776402 825.36 Client requests received
38cache_hit 13929762 778.07 Cache hits
39cache_hitpass 52996 2.96 Cache hits for pass
40cache_miss 788513 44.04 Cache misses
41backend_conn 494618 27.63 Backend conn. success
80f3cdc2 42backend_unhealthy 0 0.00 Backend conn. not attempted
088278ef
ER
43backend_busy 0 0.00 Backend conn. too many
44backend_fail 0 0.00 Backend conn. failures
45backend_reuse 351664 19.64 Backend conn. reuses
46backend_recycle 817584 45.67 Backend conn. recycles
47backend_unused 0 0.00 Backend conn. unused
80f3cdc2 48backend_toolate 868693 25.81 Backend conn. was closed
088278ef
ER
49n_srcaddr 0 . N struct srcaddr
50n_srcaddr_act 0 . N active struct srcaddr
51n_sess_mem 2200 . N struct sess_mem
52n_sess 1207 . N struct sess
53n_object 151202 . N struct object
54n_objecthead 91698 . N struct objecthead
55n_smf 326799 . N struct smf
56n_smf_frag 24687 . N small free smf
57n_smf_large 326 . N large free smf
58n_vbe_conn 26 . N struct vbe_conn
59n_bereq 212 . N struct bereq
60n_wrk 600 . N worker threads
61n_wrk_create 600 0.03 N worker threads created
62n_wrk_failed 0 0.00 N worker threads not created
63n_wrk_max 0 0.00 N worker threads limited
64n_wrk_queue 0 0.00 N queued work requests
65n_wrk_overflow 2639 0.15 N overflowed work requests
66n_wrk_drop 0 0.00 N dropped work requests
67n_backend 20 . N backends
68n_expired 472014 . N expired objects
69n_lru_nuked 165622 . N LRU nuked objects
70n_lru_saved 0 . N LRU saved objects
71n_lru_moved 6575346 . N LRU moved objects
72n_objsendfile 0 0.00 Objects sent with sendfile
73n_objwrite 14087414 786.87 Objects sent with write
74n_objoverflow 0 0.00 Objects overflowing workspace
75s_pipe 879 0.05 Total pipe
76s_pass 56935 3.18 Total pass
77s_hdrbytes 5095096301 284594.55 Total header bytes
78s_bodybytes 105139468938 5872729.09 Total body bytes
80f3cdc2
ER
79s_fetch 1669741 46.49 Total fetch
80s_req 28734002 799.12 Total Requests
81s_sess 6579080 182.90 Total Sessions
088278ef
ER
82sess_closed 211106 11.79 Session Closed
83sess_pipeline 52085 2.91 Session Pipeline
84sess_readahead 54758 3.06 Session Read Ahead
85sess_linger 14576708 814.20 Session Linger
86sess_herd 11874652 663.28 Session herd
87shm_records 626744114 35007.77 SHM records
88shm_writes 37710636 2106.39 SHM writes
89shm_flushes 32226 1.80 SHM flushes due to overflow
90shm_cont 101165 5.65 SHM MTX contention
91shm_cycles 256 0.01 SHM cycles through buffer
92sm_nreq 1857435 103.75 allocator requests
93sm_balloc 3918831616 . bytes allocated
80f3cdc2
ER
94sm_bfree 5332348928 . bytes free
95sm_nobj 85307 . outstanding allocations
088278ef
ER
96sma_nreq 0 0.00 SMA allocator requests
97sma_nbytes 0 . SMA outstanding bytes
98sms_nreq 344 0.02 SMS allocator requests
99sms_nbytes 0 . SMS outstanding bytes
80f3cdc2
ER
100sma_balloc 0 . SMA bytes allocated
101sma_bfree 0 . SMA bytes free
102sma_nobj 0 . SMA outstanding allocations
103sms_balloc 4466012 . SMS bytes allocated
104sms_bfree 4466012 . SMS bytes freed
105sms_nobj 0 . SMS outstanding allocations
088278ef
ER
106backend_req 845376 47.22 Backend requests made
107n_vcl 1 0.00 N vcl total
108n_vcl_avail 1 0.00 N vcl available
109n_vcl_discard 0 0.00 N vcl discarded
110n_purge 1 . N total active purges
111n_purge_add 1 0.00 N new purges added
112n_purge_retire 0 0.00 N old purges deleted
113n_purge_obj_test 0 0.00 N objects tested
114n_purge_re_test 0 0.00 N regexps tested against
115n_purge_dups 0 0.00 N duplicate purges removed
116hcb_nolock 0 0.00 HCB Lookups without lock
117hcb_lock 0 0.00 HCB Lookups with lock
118hcb_insert 0 0.00 HCB Inserts
119esi_parse 0 0.00 Objects ESI parsed (unlock)
120esi_errors 0 0.00 ESI parse errors (unlock)
121"""
69382e8f 122
088278ef
ER
123# process results
124split = re.compile('^\s*(?P<value>\S+)\s+(?P<key>.+)$')
125res = {}
126for line in out.split('\n'):
127 m = re.search(split, line);
128 if m:
129 res[m.group('key')] = m.group('value')
69382e8f 130
088278ef
ER
131# map for keys
132split = re.compile('^(?P<key>\S+)\s+(\d+)\s+\S+\s+(?P<value>.+)$')
133for line in sample.split('\n'):
134 m = re.search(split, line);
135 if m:
136 if res.has_key(m.group('value')):
137 value = res[m.group('value')]
138 print "%s:%s" % (m.group('key'), value),
139 else:
140 # for missing value, print -1
141 print "%s:-1" % m.group('key'),
69382e8f 142
088278ef
ER
143# print results for original script
144req = res['Client requests received']
145hit = float(res['Cache hits'])
146miss = float(res['Cache misses'])
69382e8f 147print 'varnish_requests:'+str(req)+' varnish_hitrate:'+str(round(hit / (hit + miss) * 100, 1))
This page took 0.153125 seconds and 4 git commands to generate.