@cryptotaxi247 / netdata-1 / commits / 875bc6042

some codacy fixes

lgz committed Nov 3, 2017 at 11:02 UTC 875bc604289ded4b7e9a1c9e60bb21bdd11d8915
5 files changed +90 -75
python.d/freeradius.chart.py
+1 -1
@@ -84,7 +84,7 @@ class Service(SimpleService):
84 self.sub_echo = [self.echo, RADIUS_MSG]
85 self.sub_radclient = [self.radclient, '-r', '1', '-t', '1',
86 ':'.join([self.host, self.port]), 'status', self.secret]
87 -
87 +
88 def check(self):
89 if not all([self.echo, self.radclient]):
90 self.error('Can\'t locate "radclient" binary or binary is not executable by netdata')
python.d/memcached.chart.py
-1
@@ -149,7 +149,6 @@ class Service(SocketService):
149 data[t[0]] = t[1]
150 except (IndexError, ValueError):
151 self.debug("invalid line received: " + str(line))
152 - pass
152
153 if not data:
154 self.error("received data doesn't have any records")
python.d/postgres.chart.py
+1 -1
@@ -225,7 +225,7 @@ CHARTS = {
225
226 class Service(SimpleService):
227 def __init__(self, configuration=None, name=None):
228 - super(self.__class__, self).__init__(configuration=configuration, name=name)
228 + SimpleService.__init__(self, configuration=configuration, name=name)
229 self.order = ORDER[:]
230 self.definitions = deepcopy(CHARTS)
231 self.table_stats = configuration.pop('table_stats', False)
python.d/redis.chart.py
-1
@@ -143,7 +143,6 @@ class Service(SocketService):
143 data[t[0]] = t[1]
144 except (IndexError, ValueError):
145 self.debug("invalid line received: " + str(line))
146 - pass
146
147 if not data:
148 self.error("received data doesn't have any records")
python.d/varnish.chart.py
+88 -71
@@ -2,7 +2,7 @@
2 # Description: varnish netdata python.d module
3 # Author: l2isbad
4
5 -from re import compile
5 +import re
6 from subprocess import Popen, PIPE
7
8 from bases.collection import find_binary
@@ -15,71 +15,89 @@ retries = 60
15
16 ORDER = ['session', 'hit_rate', 'chit_rate', 'expunge', 'threads', 'backend_health', 'memory_usage', 'bad', 'uptime']
17
18 -CHARTS = {'backend_health':
19 - {'lines': [['backend_conn', 'conn', 'incremental', 1, 1],
20 - ['backend_unhealthy', 'unhealthy', 'incremental', 1, 1],
21 - ['backend_busy', 'busy', 'incremental', 1, 1],
22 - ['backend_fail', 'fail', 'incremental', 1, 1],
23 - ['backend_reuse', 'reuse', 'incremental', 1, 1],
24 - ['backend_recycle', 'resycle', 'incremental', 1, 1],
25 - ['backend_toolate', 'toolate', 'incremental', 1, 1],
26 - ['backend_retry', 'retry', 'incremental', 1, 1],
27 - ['backend_req', 'req', 'incremental', 1, 1]],
28 - 'options': [None, 'Backend health', 'connections', 'Backend health', 'varnish.backend_traf', 'line']},
29 - 'bad':
30 - {'lines': [['sess_drop_b', None, 'incremental', 1, 1],
31 - ['backend_unhealthy_b', None, 'incremental', 1, 1],
32 - ['fetch_failed', None, 'incremental', 1, 1],
33 - ['backend_busy_b', None, 'incremental', 1, 1],
34 - ['threads_failed_b', None, 'incremental', 1, 1],
35 - ['threads_limited_b', None, 'incremental', 1, 1],
36 - ['threads_destroyed_b', None, 'incremental', 1, 1],
37 - ['thread_queue_len_b', 'queue_len', 'absolute', 1, 1],
38 - ['losthdr_b', None, 'incremental', 1, 1],
39 - ['esi_errors_b', None, 'incremental', 1, 1],
40 - ['esi_warnings_b', None, 'incremental', 1, 1],
41 - ['sess_fail_b', None, 'incremental', 1, 1],
42 - ['sc_pipe_overflow_b', None, 'incremental', 1, 1],
43 - ['sess_pipe_overflow_b', None, 'incremental', 1, 1]],
44 - 'options': [None, 'Misbehavior', 'problems', 'Problems summary', 'varnish.bad', 'line']},
45 - 'expunge':
46 - {'lines': [['n_expired', 'expired', 'incremental', 1, 1],
47 - ['n_lru_nuked', 'lru_nuked', 'incremental', 1, 1]],
48 - 'options': [None, 'Object expunging', 'objects', 'Cache performance', 'varnish.expunge', 'line']},
49 - 'hit_rate':
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]],
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]],
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]],
64 - 'options': [None, 'Memory usage', 'megabytes', 'Memory usage', 'varnish.memory_usage', 'stacked']},
65 - 'session':
66 - {'lines': [['sess_conn', 'sess_conn', 'incremental', 1, 1],
67 - ['client_req', 'client_requests', 'incremental', 1, 1],
68 - ['client_conn', 'client_conn', 'incremental', 1, 1],
69 - ['client_drop', 'client_drop', 'incremental', 1, 1],
70 - ['sess_dropped', 'sess_dropped', 'incremental', 1, 1]],
71 - 'options': [None, 'Sessions', 'units', 'Client metrics', 'varnish.session', 'line']},
72 - 'threads':
73 - {'lines': [['threads', None, 'absolute', 1, 1],
74 - ['threads_created', 'created', 'incremental', 1, 1],
75 - ['threads_failed', 'failed', 'incremental', 1, 1],
76 - ['threads_limited', 'limited', 'incremental', 1, 1],
77 - ['thread_queue_len', 'queue_len', 'incremental', 1, 1],
78 - ['sess_queued', 'sess_queued', 'incremental', 1, 1]],
79 - 'options': [None, 'Thread status', 'threads', 'Thread-related metrics', 'varnish.threads', 'line']},
80 - 'uptime':
81 - {'lines': [['uptime', None, 'absolute', 1, 1]],
82 - 'options': [None, 'Varnish uptime', 'seconds', 'Uptime', 'varnish.uptime', 'line']}
18 +CHARTS = {
19 + 'backend_health': {
20 + 'lines': [
21 + ['backend_conn', 'conn', 'incremental', 1, 1],
22 + ['backend_unhealthy', 'unhealthy', 'incremental', 1, 1],
23 + ['backend_busy', 'busy', 'incremental', 1, 1],
24 + ['backend_fail', 'fail', 'incremental', 1, 1],
25 + ['backend_reuse', 'reuse', 'incremental', 1, 1],
26 + ['backend_recycle', 'resycle', 'incremental', 1, 1],
27 + ['backend_toolate', 'toolate', 'incremental', 1, 1],
28 + ['backend_retry', 'retry', 'incremental', 1, 1],
29 + ['backend_req', 'req', 'incremental', 1, 1]],
30 + 'options': [None, 'Backend Health', 'connections/s', 'backend health', 'varnish.backend_health', 'line']
31 + },
32 + 'bad': {
33 + 'lines': [
34 + ['sess_drop_b', None, 'incremental', 1, 1],
35 + ['backend_unhealthy_b', None, 'incremental', 1, 1],
36 + ['fetch_failed', None, 'incremental', 1, 1],
37 + ['backend_busy_b', None, 'incremental', 1, 1],
38 + ['threads_failed_b', None, 'incremental', 1, 1],
39 + ['threads_limited_b', None, 'incremental', 1, 1],
40 + ['threads_destroyed_b', None, 'incremental', 1, 1],
41 + ['thread_queue_len_b', 'queue_len', 'absolute', 1, 1],
42 + ['losthdr_b', None, 'incremental', 1, 1],
43 + ['esi_errors_b', None, 'incremental', 1, 1],
44 + ['esi_warnings_b', None, 'incremental', 1, 1],
45 + ['sess_fail_b', None, 'incremental', 1, 1],
46 + ['sc_pipe_overflow_b', None, 'incremental', 1, 1],
47 + ['sess_pipe_overflow_b', None, 'incremental', 1, 1]],
48 + 'options': [None, 'Misbehavior', 'problems/s', 'problems summary', 'varnish.bad', 'line']
49 + },
50 + 'expunge': {
51 + 'lines': [
52 + ['n_expired', 'expired', 'incremental', 1, 1],
53 + ['n_lru_nuked', 'lru_nuked', 'incremental', 1, 1]],
54 + 'options': [None, 'Object expunging', 'objects/s', 'cache performance', 'varnish.expunge', 'line']
55 + },
56 + 'hit_rate': {
57 + 'lines': [
58 + ['cache_hit_perc', 'hit', 'absolute', 1, 100],
59 + ['cache_miss_perc', 'miss', 'absolute', 1, 100],
60 + ['cache_hitpass_perc', 'hitpass', 'absolute', 1, 100]],
61 + 'options': [None, 'All History Hit Rate Ratio', 'percent', 'cache performance', 'varnish.hit_rate', 'stacked']
62 + },
63 + 'chit_rate': {
64 + 'lines': [
65 + ['cache_hit_cperc', 'hit', 'absolute', 1, 100],
66 + ['cache_miss_cperc', 'miss', 'absolute', 1, 100],
67 + ['cache_hitpass_cperc', 'hitpass', 'absolute', 1, 100]],
68 + 'options': [None, 'Current Poll Hit Rate Ratio', 'percent', 'cache performance', 'varnish.chit_rate', 'stacked']
69 + },
70 + 'memory_usage': {
71 + 'lines': [
72 + ['s0.g_space', 'available', 'absolute', 1, 1 << 20],
73 + ['s0.g_bytes', 'allocated', 'absolute', -1, 1 << 20]],
74 + 'options': [None, 'Memory Usage', 'megabytes', 'memory usage', 'varnish.memory_usage', 'stacked']
75 + },
76 + 'session': {
77 + 'lines': [
78 + ['sess_conn', 'sess_conn', 'incremental', 1, 1],
79 + ['client_req', 'client_requests', 'incremental', 1, 1],
80 + ['client_conn', 'client_conn', 'incremental', 1, 1],
81 + ['client_drop', 'client_drop', 'incremental', 1, 1],
82 + ['sess_dropped', 'sess_dropped', 'incremental', 1, 1]],
83 + 'options': [None, 'Sessions', 'units/s', 'client metrics', 'varnish.session', 'line']
84 + },
85 + 'threads': {
86 + 'lines': [
87 + ['threads', None, 'absolute', 1, 1],
88 + ['threads_created', 'created', 'incremental', 1, 1],
89 + ['threads_failed', 'failed', 'incremental', 1, 1],
90 + ['threads_limited', 'limited', 'incremental', 1, 1],
91 + ['thread_queue_len', 'queue_len', 'incremental', 1, 1],
92 + ['sess_queued', 'sess_queued', 'incremental', 1, 1]],
93 + 'options': [None, 'Thread Status', 'threads/s', 'thread related metrics', 'varnish.threads', 'line']
94 + },
95 + 'uptime': {
96 + 'lines': [
97 + ['uptime', None, 'absolute', 1, 1]
98 + ],
99 + 'options': [None, 'Uptime', 'seconds', 'uptime', 'varnish.uptime', 'line']
100 + }
101 }
102
103
@@ -93,8 +111,8 @@ class Service(SimpleService):
111 # or
112 # VBE.default2(127.0.0.2,,81).bereq_bodybytes (old)
113 # Regex result: [('super_backend', 'beresp_hdrbytes', '0'), ('super_backend', 'beresp_bodybytes', '0')]
96 - self.rgx_bck = (compile(r'VBE.([\d\w_.]+)\(.*?\).(beresp[\w_]+)\s+(\d+)'),
97 - compile(r'VBE\.[\d\w-]+\.([\w\d_]+).(beresp[\w_]+)\s+(\d+)'))
114 + self.rgx_bck = (re.compile(r'VBE.([\d\w_.]+)\(.*?\).(beresp[\w_]+)\s+(\d+)'),
115 + re.compile(r'VBE\.[\d\w-]+\.([\w\d_]+).(beresp[\w_]+)\s+(\d+)'))
116 self.cache_prev = list()
117
118 def check(self):
@@ -107,7 +125,7 @@ class Service(SimpleService):
125 # 1. STDOUT is not empty
126 reply = self._get_raw_data()
127 if not reply:
110 - self.error('No output from \'varnishstat\' (not enough privileges?)')
128 + self.error("No output from 'varnishstat' (not enough privileges?)")
129 return False
130
131 # 2. Output is parsable (list is not empty after regex findall)
@@ -124,10 +142,9 @@ class Service(SimpleService):
142 self.backend_list = self.rgx_bck[1].findall(reply)[::2]
143 self.rgx_bck = self.rgx_bck[1]
144
127 - # We are about to start!
145 self.create_charts()
146 return True
130 -
147 +
148 def _get_raw_data(self):
149 try:
150 reply = Popen([self.varnish, '-1'], stdout=PIPE, stderr=PIPE, shell=False)