@cryptotaxi247 / netdata-1 / commits / 024f7ff23

More code cleanup

paulfantom committed Jun 19, 2016 at 15:37 UTC 024f7ff236548f27764a00bd678977c57ac8bfe5
4 files changed +34 -39
plugins.d/python.d.plugin
+3 -4
@@ -144,8 +144,8 @@ class PythonCharts(object):
144 mod.config = {None: {}}
145 for var in BASE_CONFIG:
146 try:
147 - mod.config[None][var] = getattr(var, mod)
148 - except Exception:
147 + mod.config[None][var] = getattr(mod, var)
148 + except AttributeError:
149 mod.config[None][var] = BASE_CONFIG[var]
150 return modules
151
@@ -361,7 +361,6 @@ def run():
361 if config_dir[-1] != '/':
362 config_dir += '/'
363 configfile = config_dir + "python.d.conf"
364 - print(config_dir)
364
365 try:
366 conf = read_config(configfile)
@@ -395,7 +394,7 @@ def run():
394 if v is False:
395 disabled.append(k)
396 except FileNotFoundError:
398 - modules_conf = config_dir
397 + modules_conf = config_dir + "python.d/"
398 modules_dir = main_dir.replace("plugins.d", "python.d")
399
400 # directories should end with '/'
python.d/example.chart.py
+3 -4
@@ -1,11 +1,10 @@
1 # Description: example netdata python.d plugin
2 # Author: Pawel Krupa (paulfantom)
3
4 -NAME = "example.chart.py"
5 -import sys
4 import random
5 from base import BaseService
6
7 +NAME = "example.chart.py"
8 # default module values
9 update_every = 3
10 priority = 90000
@@ -13,7 +12,7 @@ retries = 7
12
13
14 class Service(BaseService):
16 - def __init__(self,configuration=None,name=None):
15 + def __init__(self, configuration=None, name=None):
16 super().__init__(configuration=configuration)
17
18 def check(self):
@@ -24,7 +23,7 @@ class Service(BaseService):
23 print("DIMENSION random1 '' absolute 1 1")
24 return True
25
27 - def update(self,interval):
26 + def update(self, interval):
27 print("BEGIN example.python_random "+str(interval))
28 print("SET random1 = "+str(random.randint(0,100)))
29 print("END")
python.d/mysql.chart.py
+25 -25
@@ -1,8 +1,8 @@
1 # Description: MySQL netdata python.d plugin
2 # Author: Pawel Krupa (paulfantom)
3
4 -NAME = "mysql.chart.py"
4 import sys
5 +NAME = "mysql.chart.py"
6
7 # import 3rd party library to handle MySQL communication
8 try:
@@ -20,7 +20,7 @@ except ImportError:
20
21 from base import BaseService
22
23 -# default configuration (overriden by python.d.plugin)
23 +# default configuration (overridden by python.d.plugin)
24 # FIXME change password
25 config = {
26 'local': {
@@ -41,19 +41,19 @@ retries = 7
41 # query executed on MySQL server
42 QUERY = "SHOW GLOBAL STATUS"
43
44 -# charts order (can be overriden if you want less charts, or different order)
45 -ORDER = ['net',
46 - 'queries',
47 - 'handlers',
48 - 'table_locks',
49 - 'join_issues',
50 - 'sort_issues',
51 - 'tmp',
52 - 'connections',
53 - 'binlog_cache',
54 - 'threads',
55 - 'thread_cache_misses',
56 - 'innodb_io',
44 +# charts order (can be overridden if you want less charts, or different order)
45 +ORDER = ['net',
46 + 'queries',
47 + 'handlers',
48 + 'table_locks',
49 + 'join_issues',
50 + 'sort_issues',
51 + 'tmp',
52 + 'connections',
53 + 'binlog_cache',
54 + 'threads',
55 + 'thread_cache_misses',
56 + 'innodb_io',
57 'innodb_io_ops',
58 'innodb_io_pending_ops',
59 'innodb_log',
@@ -83,7 +83,7 @@ ORDER = ['net',
83 # 'chart_name_in_netdata': (
84 # "parameters defining chart (passed to CHART statement)",
85 # [ # dimensions (lines) definitions
86 -# ("dimension_name", "dimension parameters (passed to DIMENSION statement)", "additional parameter (optional)")
86 +# ("dimension_name", "dimension parameters (passed to DIMENSION statement)")
87 # ])
88 # }
89
@@ -377,8 +377,8 @@ class Service(BaseService):
377 connect_timeout=self.configuration['update_every'])
378 except Exception as e:
379 self.error(NAME + " has problem connecting to server:", e)
380 - raise RuntimeError #stop creating module, need to catch it in supervisor
381 -
380 + raise RuntimeError # stop creating module, need to catch it in supervisor
381 +
382 def _get_data(self):
383 if self.connection is None:
384 self._connect()
@@ -391,7 +391,7 @@ class Service(BaseService):
391 self.connection.close()
392 self.connection = None
393 return None
394 -
394 +
395 return dict(raw_data)
396
397 def check(self):
@@ -407,7 +407,7 @@ class Service(BaseService):
407 self.defs[name] = []
408 for line in CHARTS[name][1]:
409 self.defs[name].append(line[0])
410 -
410 +
411 idx = 0
412 data = self._get_data()
413 for name in ORDER:
@@ -418,7 +418,7 @@ class Service(BaseService):
418 str(self.priority + idx) + " " + \
419 str(self.update_every)
420 content = ""
421 - # check if server has this datapoint
421 + # check if server has this data point
422 for line in CHARTS[name][1]:
423 if line[0] in data:
424 content += "DIMENSION " + line[0] + " " + line[1] + "\n"
@@ -426,17 +426,17 @@ class Service(BaseService):
426 print(header)
427 print(content)
428 idx += 1
429 -
429 +
430 if idx == 0:
431 return False
432 return True
433
434 - def update(self,interval):
434 + def update(self, interval):
435 data = self._get_data()
436 if data is None:
437 return False
438 try:
439 - data['Thread cache misses'] = int( int(data['Threads_created']) * 10000 / int(data['Connections']))
439 + data['Thread cache misses'] = int(int(data['Threads_created']) * 10000 / int(data['Connections']))
440 except Exception:
441 pass
442 for chart, dimensions in self.defs.items():
@@ -449,5 +449,5 @@ class Service(BaseService):
449 pass
450 if len(lines) > 0:
451 print(header + lines + "END")
452 -
452 +
453 return True
python.d/python_modules/base.py
+3 -6
@@ -38,16 +38,13 @@ class BaseService(object):
38 sys.stderr.flush()
39
40 def check(self):
41 - # TODO notify about not overridden function
42 - self.error("Where is your check()?")
41 + self.error("Service " + str(self.__name__) + "doesn't implement check() function")
42 return False
43
44 def create(self):
46 - # TODO notify about not overridden function
47 - self.error("Where is your create()?")
45 + self.error("Service " + str(self.__name__) + "doesn't implement create() function?")
46 return False
47
48 def update(self):
51 - # TODO notify about not overridden function
52 - self.error("Where is your update()?")
49 + self.error("Service " + str(self.__name__) + "doesn't implement update() function")
50 return False