@cryptotaxi247 / netdata-1 / commits / f7bddbe07

Python.d PEP 8 cleanup, modules A-C (#4286)

* cpufreq.chart.py PEP 8 code cleanups Fixes formatting of nested container literals and two cases of using len() to determine if a container is empty or not. * python.d/apache.chart.py PEP 8 cleanup. Makes quotes consistent for string literals and enforces preferred formatting for container literals. * python.d/beanstalk.chart.py PEP 8 cleanup Fixes formatting of container literals. * python.d/bind_rndc.chart.py PEP 8 cleanup Fixed container literal formatting. * python.d/ceph.chart.py PEP 8 cleanup Fixed container literal formatting and line-continuation indentation. * python.d/chrony.chart.py PEP 8 cleanups Fixed container literal formatting and made string literals use consistent quotes. * python.d/cpuidle.chart.py PEP 8 cleanup Fixed container literal formatting and made string literals use consistent quotes.

Austin S. Hemmelgarn committed Sep 26, 2018 at 11:37 UTC f7bddbe07b4b606ce75bdc1cf87502b4b8986643
7 files changed +157 -138
python.d/apache.chart.py
+29 -27
@@ -26,63 +26,65 @@ CHARTS = {
26 'options': [None, 'apache Lifetime Avg. Response Size', 'bytes/request',
27 'statistics', 'apache.bytesperreq', 'area'],
28 'lines': [
29 - ["size_req"]
29 + ['size_req']
30 ]},
31 'workers': {
32 'options': [None, 'apache Workers', 'workers', 'workers', 'apache.workers', 'stacked'],
33 'lines': [
34 - ["idle"],
35 - ["busy"],
34 + ['idle'],
35 + ['busy'],
36 ]},
37 'reqpersec': {
38 'options': [None, 'apache Lifetime Avg. Requests/s', 'requests/s', 'statistics',
39 'apache.reqpersec', 'area'],
40 'lines': [
41 - ["requests_sec"]
41 + ['requests_sec']
42 ]},
43 'bytespersec': {
44 'options': [None, 'apache Lifetime Avg. Bandwidth/s', 'kilobits/s', 'statistics',
45 'apache.bytesperreq', 'area'],
46 'lines': [
47 - ["size_sec", None, 'absolute', 8, 1000]
47 + ['size_sec', None, 'absolute', 8, 1000]
48 ]},
49 'requests': {
50 'options': [None, 'apache Requests', 'requests/s', 'requests', 'apache.requests', 'line'],
51 'lines': [
52 - ["requests", None, 'incremental']
52 + ['requests', None, 'incremental']
53 ]},
54 'net': {
55 'options': [None, 'apache Bandwidth', 'kilobits/s', 'bandwidth', 'apache.net', 'area'],
56 'lines': [
57 - ["sent", None, 'incremental', 8, 1]
57 + ['sent', None, 'incremental', 8, 1]
58 ]},
59 'connections': {
60 'options': [None, 'apache Connections', 'connections', 'connections', 'apache.connections', 'line'],
61 'lines': [
62 - ["connections"]
62 + ['connections']
63 ]},
64 'conns_async': {
65 'options': [None, 'apache Async Connections', 'connections', 'connections', 'apache.conns_async', 'stacked'],
66 'lines': [
67 - ["keepalive"],
68 - ["closing"],
69 - ["writing"]
67 + ['keepalive'],
68 + ['closing'],
69 + ['writing']
70 ]}
71 }
72
73 -ASSIGNMENT = {"BytesPerReq": 'size_req',
74 - "IdleWorkers": 'idle',
75 - "IdleServers": 'idle_servers',
76 - "BusyWorkers": 'busy',
77 - "BusyServers": 'busy_servers',
78 - "ReqPerSec": 'requests_sec',
79 - "BytesPerSec": 'size_sec',
80 - "Total Accesses": 'requests',
81 - "Total kBytes": 'sent',
82 - "ConnsTotal": 'connections',
83 - "ConnsAsyncKeepAlive": 'keepalive',
84 - "ConnsAsyncClosing": 'closing',
85 - "ConnsAsyncWriting": 'writing'}
73 +ASSIGNMENT = {
74 + 'BytesPerReq': 'size_req',
75 + 'IdleWorkers': 'idle',
76 + 'IdleServers': 'idle_servers',
77 + 'BusyWorkers': 'busy',
78 + 'BusyServers': 'busy_servers',
79 + 'ReqPerSec': 'requests_sec',
80 + 'BytesPerSec': 'size_sec',
81 + 'Total Accesses': 'requests',
82 + 'Total kBytes': 'sent',
83 + 'ConnsTotal': 'connections',
84 + 'ConnsAsyncKeepAlive': 'keepalive',
85 + 'ConnsAsyncClosing': 'closing',
86 + 'ConnsAsyncWriting': 'writing'
87 +}
88
89
90 class Service(UrlService):
@@ -103,8 +105,8 @@ class Service(UrlService):
105 for chart in self.definitions:
106 if chart == 'workers':
107 lines = self.definitions[chart]['lines']
106 - lines[0] = ["idle_servers", 'idle']
107 - lines[1] = ["busy_servers", 'busy']
108 + lines[0] = ['idle_servers', 'idle']
109 + lines[1] = ['busy_servers', 'busy']
110 opts = self.definitions[chart]['options']
111 opts[1] = opts[1].replace('apache', 'lighttpd')
112 opts[4] = opts[4].replace('apache', 'lighttpd')
@@ -121,7 +123,7 @@ class Service(UrlService):
123 data = dict()
124
125 for row in raw_data.split('\n'):
124 - tmp = row.split(":")
126 + tmp = row.split(':')
127 if tmp[0] in ASSIGNMENT:
128 try:
129 data[ASSIGNMENT[tmp[0]]] = int(float(tmp[1]))
python.d/beanstalk.chart.py
+11 -7
@@ -115,7 +115,7 @@ def tube_chart_template(name):
115 '{0}_connections'.format(name),
116 '{0}_commands'.format(name),
117 '{0}_pause'.format(name)
118 - ]
118 + ]
119 family = 'tube {0}'.format(name)
120
121 charts = {
@@ -123,7 +123,8 @@ def tube_chart_template(name):
123 'options': [None, 'Job Rate', 'jobs/s', family, 'beanstalk.jobs_rate', 'area'],
124 'lines': [
125 ['_'.join([name, 'total-jobs']), 'jobs', 'incremental']
126 - ]},
126 + ]
127 + },
128 order[1]: {
129 'options': [None, 'Jobs', 'jobs', family, 'beanstalk.jobs', 'stacked'],
130 'lines': [
@@ -132,27 +133,30 @@ def tube_chart_template(name):
133 ['_'.join([name, 'current-jobs-reserved']), 'reserved'],
134 ['_'.join([name, 'current-jobs-delayed']), 'delayed'],
135 ['_'.join([name, 'current-jobs-buried']), 'buried']
135 - ]},
136 + ]
137 + },
138 order[2]: {
139 'options': [None, 'Connections', 'connections', family, 'beanstalk.connections', 'stacked'],
140 'lines': [
141 ['_'.join([name, 'current-using']), 'using'],
142 ['_'.join([name, 'current-waiting']), 'waiting'],
143 ['_'.join([name, 'current-watching']), 'watching']
142 - ]},
144 + ]
145 + },
146 order[3]: {
147 'options': [None, 'Commands', 'commands/s', family, 'beanstalk.commands', 'stacked'],
148 'lines': [
149 ['_'.join([name, 'cmd-delete']), 'deletes', 'incremental'],
150 ['_'.join([name, 'cmd-pause-tube']), 'pauses', 'incremental']
148 - ]},
151 + ]
152 + },
153 order[4]: {
154 'options': [None, 'Pause', 'seconds', family, 'beanstalk.pause', 'stacked'],
155 'lines': [
156 ['_'.join([name, 'pause']), 'since'],
157 ['_'.join([name, 'pause-time-left']), 'left']
154 - ]}
155 -
158 + ]
159 + }
160 }
161
162 return order, charts
python.d/bind_rndc.chart.py
+33 -39
@@ -36,56 +36,50 @@ CHARTS = {
36 ['nms_dropped_queries', 'dropped_queries', 'incremental'],
37 ]},
38 'incoming_queries': {
39 - 'options': [None, 'Incoming Queries', 'queries', 'incoming queries',
40 - 'bind_rndc.incoming_queries', 'line'],
39 + 'options': [None, 'Incoming Queries', 'queries', 'incoming queries', 'bind_rndc.incoming_queries', 'line'],
40 'lines': [
41 ]},
42 'outgoing_queries': {
44 - 'options': [None, 'Outgoing Queries', 'queries', 'outgoing queries',
45 - 'bind_rndc.outgoing_queries', 'line'],
43 + 'options': [None, 'Outgoing Queries', 'queries', 'outgoing queries', 'bind_rndc.outgoing_queries', 'line'],
44 'lines': [
45 ]},
46 'named_stats_size': {
49 - 'options': [None, 'Named Stats File Size', 'MB', 'file size',
50 - 'bind_rndc.stats_size', 'line'],
47 + 'options': [None, 'Named Stats File Size', 'MB', 'file size', 'bind_rndc.stats_size', 'line'],
48 'lines': [
49 ['stats_size', None, 'absolute', 1, 1 << 20]
53 - ]}
50 + ]
51 + }
52 }
53
54 NMS = {
57 - 'nms_requests':
58 - ['IPv4 requests received',
59 - 'IPv6 requests received',
60 - 'TCP requests received',
61 - 'requests with EDNS(0) receive'],
62 - 'nms_responses':
63 - ['responses sent',
64 - 'truncated responses sent',
65 - 'responses with EDNS(0) sent',
66 - 'requests with unsupported EDNS version received'],
67 - 'nms_failure':
68 - ['other query failures',
69 - 'queries resulted in SERVFAIL'],
70 - 'nms_auth_answer':
71 - ['queries resulted in authoritative answer'],
72 - 'nms_non_auth_answer':
73 - ['queries resulted in non authoritative answer'],
74 - 'nms_nxrrset':
75 - ['queries resulted in nxrrset'],
76 - 'nms_success':
77 - ['queries resulted in successful answer'],
78 - 'nms_nxdomain':
79 - ['queries resulted in NXDOMAIN'],
80 - 'nms_recursion':
81 - ['queries caused recursion'],
82 - 'nms_duplicate':
83 - ['duplicate queries received'],
84 - 'nms_rejected_queries':
85 - ['auth queries rejected',
86 - 'recursive queries rejected'],
87 - 'nms_dropped_queries':
88 - ['queries dropped']
55 + 'nms_requests': [
56 + 'IPv4 requests received',
57 + 'IPv6 requests received',
58 + 'TCP requests received',
59 + 'requests with EDNS(0) receive'
60 + ],
61 + 'nms_responses': [
62 + 'responses sent',
63 + 'truncated responses sent',
64 + 'responses with EDNS(0) sent',
65 + 'requests with unsupported EDNS version received'
66 + ],
67 + 'nms_failure': [
68 + 'other query failures',
69 + 'queries resulted in SERVFAIL'
70 + ],
71 + 'nms_auth_answer': ['queries resulted in authoritative answer'],
72 + 'nms_non_auth_answer': ['queries resulted in non authoritative answer'],
73 + 'nms_nxrrset': ['queries resulted in nxrrset'],
74 + 'nms_success': ['queries resulted in successful answer'],
75 + 'nms_nxdomain': ['queries resulted in NXDOMAIN'],
76 + 'nms_recursion': ['queries caused recursion'],
77 + 'nms_duplicate': ['duplicate queries received'],
78 + 'nms_rejected_queries': [
79 + 'auth queries rejected',
80 + 'recursive queries rejected'
81 + ],
82 + 'nms_dropped_queries': ['queries dropped']
83 }
84
85 STATS = ['Name Server Statistics', 'Incoming Queries', 'Outgoing Queries']
python.d/ceph.chart.py
+41 -25
@@ -18,10 +18,22 @@ update_every = 10
18 priority = 60000
19 retries = 60
20
21 -ORDER = ['general_usage', 'general_objects', 'general_bytes', 'general_operations',
22 - 'general_latency', 'pool_usage', 'pool_objects', 'pool_read_bytes',
23 - 'pool_write_bytes', 'pool_read_operations', 'pool_write_operations', 'osd_usage',
24 - 'osd_apply_latency', 'osd_commit_latency']
21 +ORDER = [
22 + 'general_usage',
23 + 'general_objects',
24 + 'general_bytes',
25 + 'general_operations',
26 + 'general_latency',
27 + 'pool_usage',
28 + 'pool_objects',
29 + 'pool_read_bytes',
30 + 'pool_write_bytes',
31 + 'pool_read_operations',
32 + 'pool_write_operations',
33 + 'osd_usage',
34 + 'osd_apply_latency',
35 + 'osd_commit_latency'
36 +]
37
38 CHARTS = {
39 'general_usage': {
@@ -164,11 +176,11 @@ class Service(SimpleService):
176 pool['name'],
177 'absolute', 1, 1024])
178 self.definitions['pool_read_operations']['lines'].append(['read_operations_{0}'.format(pool['name']),
167 - pool['name'],
168 - 'absolute'])
179 + pool['name'],
180 + 'absolute'])
181 self.definitions['pool_write_operations']['lines'].append(['write_operations_{0}'.format(pool['name']),
170 - pool['name'],
171 - 'absolute'])
182 + pool['name'],
183 + 'absolute'])
184
185 # OSD lines
186 for osd in sorted(self._get_osd_df()['nodes']):
@@ -230,16 +242,17 @@ class Service(SimpleService):
242 apply_latency += perf['perf_stats']['apply_latency_ms']
243 commit_latency += perf['perf_stats']['commit_latency_ms']
244
233 - return {'general_usage': int(status['kb_used']),
234 - 'general_available': int(status['kb_avail']),
235 - 'general_objects': int(status['num_objects']),
236 - 'general_read_bytes': read_bytes_sec,
237 - 'general_write_bytes': write_bytes_sec,
238 - 'general_read_operations': read_op_per_sec,
239 - 'general_write_operations': write_op_per_sec,
240 - 'general_apply_latency': apply_latency,
241 - 'general_commit_latency': commit_latency
242 - }
245 + return {
246 + 'general_usage': int(status['kb_used']),
247 + 'general_available': int(status['kb_avail']),
248 + 'general_objects': int(status['num_objects']),
249 + 'general_read_bytes': read_bytes_sec,
250 + 'general_write_bytes': write_bytes_sec,
251 + 'general_read_operations': read_op_per_sec,
252 + 'general_write_operations': write_op_per_sec,
253 + 'general_apply_latency': apply_latency,
254 + 'general_commit_latency': commit_latency
255 + }
256
257 @staticmethod
258 def _get_pool_usage(pool):
@@ -263,11 +276,12 @@ class Service(SimpleService):
276 Get read/write kb and operations in a pool
277 :return: A pool dict with both read/write bytes and operations.
278 """
266 - return {'read_{0}'.format(pool['pool_name']): int(pool['client_io_rate'].get('read_bytes_sec', 0)),
267 - 'write_{0}'.format(pool['pool_name']): int(pool['client_io_rate'].get('write_bytes_sec', 0)),
268 - 'read_operations_{0}'.format(pool['pool_name']): int(pool['client_io_rate'].get('read_op_per_sec', 0)),
269 - 'write_operations_{0}'.format(pool['pool_name']): int(pool['client_io_rate'].get('write_op_per_sec', 0))
270 - }
279 + return {
280 + 'read_{0}'.format(pool['pool_name']): int(pool['client_io_rate'].get('read_bytes_sec', 0)),
281 + 'write_{0}'.format(pool['pool_name']): int(pool['client_io_rate'].get('write_bytes_sec', 0)),
282 + 'read_operations_{0}'.format(pool['pool_name']): int(pool['client_io_rate'].get('read_op_per_sec', 0)),
283 + 'write_operations_{0}'.format(pool['pool_name']): int(pool['client_io_rate'].get('write_op_per_sec', 0))
284 + }
285
286 @staticmethod
287 def _get_osd_usage(osd):
@@ -283,8 +297,10 @@ class Service(SimpleService):
297 Get ceph osd apply and commit latency
298 :return: A osd dict with osd name's key with both apply and commit latency values
299 """
286 - return {'apply_latency_osd.{0}'.format(osd['id']): osd['perf_stats']['apply_latency_ms'],
287 - 'commit_latency_osd.{0}'.format(osd['id']): osd['perf_stats']['commit_latency_ms']}
300 + return {
301 + 'apply_latency_osd.{0}'.format(osd['id']): osd['perf_stats']['apply_latency_ms'],
302 + 'commit_latency_osd.{0}'.format(osd['id']): osd['perf_stats']['commit_latency_ms']
303 + }
304
305 def _get_df(self):
306 """
python.d/chrony.chart.py
+36 -32
@@ -14,66 +14,70 @@ retries = 10
14 ORDER = ['system', 'offsets', 'stratum', 'root', 'frequency', 'residualfreq', 'skew']
15
16 CHARTS = {
17 - # id: {
18 - # 'options': [name, title, units, family, context, charttype],
19 - # 'lines': [
20 - # [unique_dimension_name, name, algorithm, multiplier, divisor]
21 - # ]}
17 'system': {
23 - 'options': [None, "Chrony System Time Deltas", "microseconds", 'system', 'chrony.system', 'area'],
18 + 'options': [None, 'Chrony System Time Deltas', 'microseconds', 'system', 'chrony.system', 'area'],
19 'lines': [
25 - ['timediff', 'system time', 'absolute', 1, 1000]
26 - ]},
20 + ['timediff', 'system time', 'absolute', 1, 1000]
21 + ]
22 + },
23 'offsets': {
28 - 'options': [None, "Chrony System Time Offsets", "microseconds", 'system', 'chrony.offsets', 'area'],
24 + 'options': [None, 'Chrony System Time Offsets', 'microseconds', 'system', 'chrony.offsets', 'area'],
25 'lines': [
26 ['lastoffset', 'last offset', 'absolute', 1, 1000],
31 - ['rmsoffset', 'RMS offset', 'absolute', 1, 1000]
32 - ]},
27 + ['rmsoffset', 'RMS offset', 'absolute', 1, 1000]
28 + ]
29 + },
30 'stratum': {
34 - 'options': [None, "Chrony Stratum", "stratum", 'root', 'chrony.stratum', 'line'],
31 + 'options': [None, 'Chrony Stratum', 'stratum', 'root', 'chrony.stratum', 'line'],
32 'lines': [
33 ['stratum', None, 'absolute', 1, 1]
37 - ]},
34 + ]
35 + },
36 'root': {
39 - 'options': [None, "Chrony Root Delays", "milliseconds", 'root', 'chrony.root', 'line'],
37 + 'options': [None, 'Chrony Root Delays', 'milliseconds', 'root', 'chrony.root', 'line'],
38 'lines': [
41 - ['rootdelay', 'delay', 'absolute', 1, 1000000],
39 + ['rootdelay', 'delay', 'absolute', 1, 1000000],
40 ['rootdispersion', 'dispersion', 'absolute', 1, 1000000]
43 - ]},
41 + ]
42 + },
43 'frequency': {
45 - 'options': [None, "Chrony Frequency", "ppm", 'frequencies', 'chrony.frequency', 'area'],
44 + 'options': [None, 'Chrony Frequency', 'ppm', 'frequencies', 'chrony.frequency', 'area'],
45 'lines': [
46 ['frequency', None, 'absolute', 1, 1000]
48 - ]},
47 + ]
48 + },
49 'residualfreq': {
50 - 'options': [None, "Chrony Residual frequency", "ppm", 'frequencies', 'chrony.residualfreq', 'area'],
50 + 'options': [None, 'Chrony Residual frequency', 'ppm', 'frequencies', 'chrony.residualfreq', 'area'],
51 'lines': [
52 ['residualfreq', 'residual frequency', 'absolute', 1, 1000]
53 - ]},
53 + ]
54 + },
55 'skew': {
55 - 'options': [None, "Chrony Skew, error bound on frequency", "ppm", 'frequencies', 'chrony.skew', 'area'],
56 + 'options': [None, 'Chrony Skew, error bound on frequency', 'ppm', 'frequencies', 'chrony.skew', 'area'],
57 'lines': [
58 ['skew', None, 'absolute', 1, 1000]
58 - ]}
59 + ]
60 + }
61 }
62
61 -CHRONY = [('Frequency', 'frequency', 1e3),
62 - ('Last offset', 'lastoffset', 1e9),
63 - ('RMS offset', 'rmsoffset', 1e9),
64 - ('Residual freq', 'residualfreq', 1e3),
65 - ('Root delay', 'rootdelay', 1e9),
66 - ('Root dispersion', 'rootdispersion', 1e9),
67 - ('Skew', 'skew', 1e3),
68 - ('Stratum', 'stratum', 1),
69 - ('System time', 'timediff', 1e9)]
63 +CHRONY = [
64 + ('Frequency', 'frequency', 1e3),
65 + ('Last offset', 'lastoffset', 1e9),
66 + ('RMS offset', 'rmsoffset', 1e9),
67 + ('Residual freq', 'residualfreq', 1e3),
68 + ('Root delay', 'rootdelay', 1e9),
69 + ('Root dispersion', 'rootdispersion', 1e9),
70 + ('Skew', 'skew', 1e3),
71 + ('Stratum', 'stratum', 1),
72 + ('System time', 'timediff', 1e9)
73 +]
74
75
76 class Service(ExecutableService):
77 def __init__(self, configuration=None, name=None):
78 ExecutableService.__init__(
79 self, configuration=configuration, name=name)
76 - self.command = "chronyc -n tracking"
80 + self.command = 'chronyc -n tracking'
81 self.order = ORDER
82 self.definitions = CHARTS
83
python.d/cpufreq.chart.py
+4 -4
@@ -19,7 +19,8 @@ CHARTS = {
19 'options': [None, 'CPU Clock', 'MHz', 'cpufreq', 'cpufreq.cpufreq', 'line'],
20 'lines': [
21 # lines are created dynamically in `check()` method
22 - ]}
22 + ]
23 + }
24 }
25
26
@@ -94,7 +95,7 @@ class Service(SimpleService):
95 self.assignment[cpu]['accurate'] = path
96 self.accurate_last[cpu] = {}
97
97 - if len(self.assignment) == 0:
98 + if not self.assignment:
99 self.accurate_exists = False
100
101 for path in glob.glob(self.sys_dir + '/system/cpu/cpu*/cpufreq/scaling_cur_freq'):
@@ -104,7 +105,7 @@ class Service(SimpleService):
105 self.assignment[cpu] = {}
106 self.assignment[cpu]['inaccurate'] = path
107
107 - if len(self.assignment) == 0:
108 + if not self.assignment:
109 self.error("couldn't find a method to read cpufreq statistics")
110 return False
111
@@ -112,4 +113,3 @@ class Service(SimpleService):
113 self.definitions[ORDER[0]]['lines'].append([name, name, 'absolute', 1, 1000])
114
115 return True
115 -
python.d/cpuidle.chart.py
+3 -4
@@ -3,13 +3,13 @@
3 # Author: Steven Noonan (tycho)
4 # SPDX-License-Identifier: GPL-3.0+
5
6 +import ctypes
7 import glob
8 import os
9 import platform
10
11 from bases.FrameworkServices.SimpleService import SimpleService
12
12 -import ctypes
13 syscall = ctypes.CDLL('libc.so.6').syscall
14
15 # default module values (can be overridden per job in `config`)
@@ -108,7 +108,7 @@ class Service(SimpleService):
108
109 def check(self):
110 if self.__gettid() is None:
111 - self.error("Cannot get thread ID. Stats would be completely broken.")
111 + self.error('Cannot get thread ID. Stats would be completely broken.')
112 return False
113
114 for path in sorted(glob.glob(self.sys_dir + '/cpu*/cpuidle/state*/name')):
@@ -141,9 +141,8 @@ class Service(SimpleService):
141 # Sort order by kernel-specified CPU index
142 self.order.sort(key=lambda x: int(x.split('_')[0][3:]))
143
144 - if len(self.definitions) == 0:
144 + if not self.definitions:
145 self.error("couldn't find cstate stats")
146 return False
147
148 return True
149 -