"varnish" module update
lgz committed
Oct 16, 2017 at 11:47 UTC
c399475dadf114e56923c16beb144b9605a04e55
1 file changed
+24
-31
python.d/varnish.chart.py
+24
-31
@@ -2,10 +2,12 @@
2
# Description: varnish netdata python.d module
3
# Author: l2isbad
4
5
-from base import SimpleService
5
from re import compile
6
from subprocess import Popen, PIPE
7
8
+from bases.collection import find_binary
9
+from bases.FrameworkServices.SimpleService import SimpleService
10
+
11
# default module values (can be overridden per job in `config`)
12
# update_every = 2
13
priority = 60000
@@ -48,12 +50,14 @@ CHARTS = {'backend_health':
50
{'lines': [['cache_hit_perc', 'hit', 'absolute', 1, 100],
51
['cache_miss_perc', 'miss', 'absolute', 1, 100],
52
['cache_hitpass_perc', 'hitpass', 'absolute', 1, 100]],
51
- 'options': [None, 'All history hit rate ratio','percent', 'Cache performance', 'varnish.hit_rate', 'stacked']},
53
+ 'options': [None, 'All history hit rate ratio','percent', 'Cache performance',
54
+ 'varnish.hit_rate', 'stacked']},
55
'chit_rate':
56
{'lines': [['cache_hit_cperc', 'hit', 'absolute', 1, 100],
57
['cache_miss_cperc', 'miss', 'absolute', 1, 100],
58
['cache_hitpass_cperc', 'hitpass', 'absolute', 1, 100]],
56
- 'options': [None, 'Current poll hit rate ratio','percent', 'Cache performance', 'varnish.chit_rate', 'stacked']},
59
+ 'options': [None, 'Current poll hit rate ratio','percent', 'Cache performance',
60
+ 'varnish.chit_rate', 'stacked']},
61
'memory_usage':
62
{'lines': [['s0.g_space', 'available', 'absolute', 1, 1048576],
63
['s0.g_bytes', 'allocated', 'absolute', -1, 1048576]],
@@ -82,7 +86,7 @@ CHARTS = {'backend_health':
86
class Service(SimpleService):
87
def __init__(self, configuration=None, name=None):
88
SimpleService.__init__(self, configuration=configuration, name=name)
85
- self.varnish = self.find_binary('varnishstat')
89
+ self.varnish = find_binary('varnishstat')
90
self.rgx_all = compile(r'([A-Z]+\.)?([\d\w_.]+)\s+(\d+)')
91
# Could be
92
# VBE.boot.super_backend.pipe_hdrbyte (new)
@@ -122,8 +126,6 @@ class Service(SimpleService):
126
127
# We are about to start!
128
self.create_charts()
125
-
126
- self.info('Plugin was started successfully')
129
return True
130
131
def _get_raw_data(self):
@@ -152,10 +154,10 @@ class Service(SimpleService):
154
return None
155
156
# 1. ALL data from 'varnishstat -1'. t - type(MAIN, MEMPOOL etc)
155
- to_netdata = dict([(k, int(v)) for t, k, v in data_all])
157
+ to_netdata = dict((k, int(v)) for t, k, v in data_all)
158
159
# 2. ADD backend statistics
158
- to_netdata.update(dict([('_'.join([n, k]), int(v)) for n, k, v in data_backend]))
160
+ to_netdata.update(dict(('_'.join([n, k]), int(v)) for n, k, v in data_backend))
161
162
# 3. ADD additional keys to dict
163
# 3.1 Cache hit/miss/hitpass OVERALL in percent
@@ -169,41 +171,33 @@ class Service(SimpleService):
171
if self.cache_prev:
172
cache_summary = sum([to_netdata.get('cache_hit', 0), to_netdata.get('cache_miss', 0),
173
to_netdata.get('cache_hitpass', 0)]) - sum(self.cache_prev)
172
- to_netdata['cache_hit_cperc'] = find_percent(to_netdata.get('cache_hit', 0) - self.cache_prev[0], cache_summary, 10000)
173
- to_netdata['cache_miss_cperc'] = find_percent(to_netdata.get('cache_miss', 0) - self.cache_prev[1], cache_summary, 10000)
174
- to_netdata['cache_hitpass_cperc'] = find_percent(to_netdata.get('cache_hitpass', 0) - self.cache_prev[2], cache_summary, 10000)
174
+ to_netdata['cache_hit_cperc'] = find_percent(to_netdata.get('cache_hit', 0)
175
+ - self.cache_prev[0], cache_summary, 10000)
176
+ to_netdata['cache_miss_cperc'] = find_percent(to_netdata.get('cache_miss', 0)
177
+ - self.cache_prev[1], cache_summary, 10000)
178
+ to_netdata['cache_hitpass_cperc'] = find_percent(to_netdata.get('cache_hitpass', 0)
179
+ - self.cache_prev[2], cache_summary, 10000)
180
else:
181
to_netdata['cache_hit_cperc'] = 0
182
to_netdata['cache_miss_cperc'] = 0
183
to_netdata['cache_hitpass_cperc'] = 0
184
180
- self.cache_prev = [to_netdata.get('cache_hit', 0), to_netdata.get('cache_miss', 0), to_netdata.get('cache_hitpass', 0)]
185
+ self.cache_prev = [to_netdata.get('cache_hit', 0),
186
+ to_netdata.get('cache_miss', 0),
187
+ to_netdata.get('cache_hitpass', 0)]
188
189
# 3.3 Problems summary chart
183
- for elem in ['backend_busy', 'backend_unhealthy', 'esi_errors', 'esi_warnings', 'losthdr', 'sess_drop', 'sc_pipe_overflow',
184
- 'sess_fail', 'sess_pipe_overflow', 'threads_destroyed', 'threads_failed', 'threads_limited', 'thread_queue_len']:
190
+ for elem in ['backend_busy', 'backend_unhealthy', 'esi_errors',
191
+ 'esi_warnings', 'losthdr', 'sess_drop', 'sc_pipe_overflow',
192
+ 'sess_fail', 'sess_pipe_overflow', 'threads_destroyed',
193
+ 'threads_failed', 'threads_limited', 'thread_queue_len']:
194
if to_netdata.get(elem) is not None:
195
to_netdata[''.join([elem, '_b'])] = to_netdata.get(elem)
196
188
- # Ready steady go!
197
return to_netdata
198
199
def create_charts(self):
192
- # If 'all_charts' is true...ALL charts are displayed. If no only default + 'extra_charts'
193
- #if self.configuration.get('all_charts'):
194
- # self.order = EXTRA_ORDER
195
- #else:
196
- # try:
197
- # extra_charts = list(filter(lambda chart: chart in EXTRA_ORDER, self.extra_charts.split()))
198
- # except (AttributeError, NameError, ValueError):
199
- # self.error('Extra charts disabled.')
200
- # extra_charts = []
201
-
200
self.order = ORDER[:]
203
- #self.order.extend(extra_charts)
204
-
205
- # Create static charts
206
- #self.definitions = {chart: values for chart, values in CHARTS.items() if chart in self.order}
201
self.definitions = CHARTS
202
203
# Create dynamic backend charts
@@ -227,5 +221,4 @@ def find_percent(value1, value2, multiply):
221
# If value2 is 0 return 0
222
if not value2:
223
return 0
230
- else:
231
- return round(float(value1) / float(value2) * multiply)
224
+ return round(float(value1) / float(value2) * multiply)