proper time alignement
paulfantom committed
Jun 12, 2016 at 13:42 UTC
d062ad4d2b7dbbc29bb6ead09ad99ac1d0d3de2d
1 file changed
+12
-17
plugins.d/python.d.plugin
+12
-17
@@ -24,9 +24,7 @@ class PythonCharts(object):
24
modules_configs='../conf.d/'):
25
self.first_run = True
26
if interval is None:
27
- self.interval = 1
28
- else:
29
- self.interval = interval
27
+ interval = 1
28
self.default_priority = 90000
29
# check if plugin directory exists
30
if not os.path.isdir(modules_path):
@@ -54,28 +52,25 @@ class PythonCharts(object):
52
53
self.load_configs()
54
57
- # set last execution and execution frequency dict
55
+ # set timetable dict (last execution, next execution and frequency)
56
+ # set priorities
57
self.timetable = {}
58
for m in self.modules:
60
- if self.interval is not None:
61
- interval = self.interval
62
- else:
59
+ try:
60
+ m.priority = int(m.priority)
61
+ except (AttributeError,ValueError):
62
+ m.priority = self.default_priority
63
+
64
+ if interval is None:
65
try:
66
interval = int(m.update_every)
67
except (AttributeError, ValueError):
68
interval = 1
69
70
now = time.time()
69
- self.timetable[m.__name__] = {'last' : 0,
70
- 'next' : now,
71
+ self.timetable[m.__name__] = {'last' : now,
72
+ 'next' : now - (now % interval) + interval,
73
'freq' : interval}
72
- # set priorities
73
- for m in self.modules:
74
- try:
75
- m.priority = int(m.priority)
76
- except (AttributeError,ValueError):
77
- m.priority = self.default_priority
78
-
74
75
def import_plugin(self, path, name=None):
76
if name is None:
@@ -197,6 +192,7 @@ class PythonCharts(object):
192
sys.stdout.write("END\n")
193
sys.stdout.flush()
194
self.timetable[mod.__name__]['last'] = t_start
195
+ self.first_run = False
196
197
def update(self):
198
self.first_run = True
@@ -207,7 +203,6 @@ class PythonCharts(object):
203
self.update_module(mod)
204
next_runs.append(self.timetable[mod.__name__]['next'])
205
time.sleep(min(next_runs) - time.time())
210
- self.first_run = False
206
207
208
def read_config(path):