even more comments
paulfantom committed
Jun 19, 2016 at 23:11 UTC
412c6d23bf843e5218fbc7b0edb4e4a5513c423d
3 files changed
+63
-3
plugins.d/python.d.plugin
-2
@@ -152,7 +152,6 @@ class PythonCharts(object):
152
:param modules: list
153
:return: list
154
"""
155
-
155
for mod in modules:
156
configfile = self.configs + mod.__name__ + ".conf"
157
if os.path.isfile(configfile):
@@ -192,7 +191,6 @@ class PythonCharts(object):
191
:param config: dict
192
:return: dict
193
"""
195
-
194
# get default values
195
defaults = {}
196
for key in BASE_CONFIG:
python.d/mysql.chart.py
+25
-1
@@ -343,7 +343,11 @@ class Service(BaseService):
343
self.defs = {}
344
345
def _parse_config(self, configuration):
346
- # parse configuration to collect data from mysql server
346
+ """
347
+ Parse configuration to collect data from MySQL server
348
+ :param configuration: dict
349
+ :return: dict
350
+ """
351
if self.name is None:
352
self.name = 'local'
353
if 'user' not in configuration:
@@ -369,6 +373,9 @@ class Service(BaseService):
373
return configuration
374
375
def _connect(self):
376
+ """
377
+ Try to connect to MySQL server
378
+ """
379
try:
380
self.connection = MySQLdb.connect(user=self.configuration['user'],
381
passwd=self.configuration['password'],
@@ -382,6 +389,10 @@ class Service(BaseService):
389
raise RuntimeError
390
391
def _get_data(self):
392
+ """
393
+ Get raw data from MySQL server
394
+ :return: dict
395
+ """
396
if self.connection is None:
397
try:
398
self._connect()
@@ -400,6 +411,10 @@ class Service(BaseService):
411
return dict(raw_data)
412
413
def check(self):
414
+ """
415
+ Check if service is able to connect to server
416
+ :return: boolean
417
+ """
418
try:
419
self.connection = self._connect()
420
return True
@@ -408,6 +423,10 @@ class Service(BaseService):
423
return False
424
425
def create(self):
426
+ """
427
+ Create graphs
428
+ :return: boolean
429
+ """
430
for name in ORDER:
431
self.defs[name] = []
432
for line in CHARTS[name][1]:
@@ -437,6 +456,11 @@ class Service(BaseService):
456
return True
457
458
def update(self, interval):
459
+ """
460
+ Update data on graphs
461
+ :param interval: int
462
+ :return: boolean
463
+ """
464
data = self._get_data()
465
if data is None:
466
return False
python.d/python_modules/base.py
+38
@@ -6,7 +6,16 @@ import sys
6
7
8
class BaseService(object):
9
+ """
10
+ Prototype of Service class.
11
+ Implemented basic functionality to run jobs by `python.d.plugin`
12
+ """
13
def __init__(self, configuration=None, name=None):
14
+ """
15
+ This needs to be initialized in child classes
16
+ :param configuration: dict
17
+ :param name: str
18
+ """
19
if configuration is None:
20
self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
21
raise RuntimeError
@@ -17,12 +26,29 @@ class BaseService(object):
26
self.execution_name = ""
27
28
def _extract_base_config(self, config):
29
+ """
30
+ Get basic parameters to run service
31
+ Minimum config:
32
+ config = {'update_every':1,
33
+ 'priority':100000,
34
+ 'retries':0}
35
+ :param config: dict
36
+ """
37
self.update_every = int(config['update_every'])
38
self.priority = int(config['priority'])
39
self.retries = int(config['retries'])
40
self.retries_left = self.retries
41
42
def create_timetable(self, freq=None):
43
+ """
44
+ Create service timetable.
45
+ `freq` is optional
46
+ Example:
47
+ timetable = {'last': 1466370091.3767564,
48
+ 'next': 1466370092,
49
+ 'freq': 1}
50
+ :param freq: int
51
+ """
52
if freq is None:
53
freq = self.update_every
54
now = time()
@@ -38,13 +64,25 @@ class BaseService(object):
64
sys.stderr.flush()
65
66
def check(self):
67
+ """
68
+ check() prototype
69
+ :return: boolean
70
+ """
71
self.error("Service " + str(self.__name__) + "doesn't implement check() function")
72
return False
73
74
def create(self):
75
+ """
76
+ create() prototype
77
+ :return: boolean
78
+ """
79
self.error("Service " + str(self.__name__) + "doesn't implement create() function?")
80
return False
81
82
def update(self):
83
+ """
84
+ update() prototype
85
+ :return: boolean
86
+ """
87
self.error("Service " + str(self.__name__) + "doesn't implement update() function")
88
return False