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