microseconds fix2
lgz committed
Oct 27, 2017 at 10:06 UTC
4572d29859d0f3d1bc7e5e5156f683c232022fca
1 file changed
+8
-13
python.d/python_modules/bases/FrameworkServices/SimpleService.py
+8
-13
@@ -173,8 +173,11 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec
173
174
self.sleep_until_next_run()
175
176
+ if job.PREV_UPDATE:
177
+ job.SINCE_UPDATE = int((job.START_RUN - job.PREV_UPDATE) * 1e6)
178
+
179
try:
177
- updated = self.update()
180
+ updated = self.update(interval=job.SINCE_UPDATE)
181
except Exception as error:
182
self.error('update() unhandled exception: {error}'.format(error=error))
183
updated = False
@@ -183,6 +186,8 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec
186
if not self.manage_retries():
187
return
188
else:
189
+ job.ELAPSED = int((time() - job.START_RUN) * 1e3)
190
+ job.PREV_UPDATE = job.START_RUN
191
job.RETRIES, job.PENALTY = 0, 0
192
safe_print(RUNTIME_CHART_UPDATE.format(job_name=self.name,
193
since_last=job.SINCE_UPDATE,
@@ -192,7 +197,7 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec
197
elapsed=job.ELAPSED if updated else '-',
198
retries=job.RETRIES_MAX - job.RETRIES))
199
195
- def update(self):
200
+ def update(self, interval):
201
"""
202
:return:
203
"""
@@ -204,16 +209,6 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec
209
self.debug('get_data() returned incorrect type data')
210
return False
211
207
- job = self._runtime_counters
208
- current_time = time()
209
-
210
- if job.PREV_UPDATE:
211
- job.SINCE_UPDATE = int((current_time - job.PREV_UPDATE) * 1e6)
212
- job.PREV_UPDATE = current_time
213
- else:
214
- job.PREV_UPDATE = current_time
215
- job.ELAPSED = int((current_time - job.START_RUN) * 1e3)
216
-
212
charts_updated = False
213
214
for chart in self.charts.penalty_exceeded(penalty_max=CHART_OBSOLETE_PENALTY):
@@ -244,7 +239,7 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec
239
240
if dimension_updated:
241
charts_updated = True
247
- safe_print(''.join([chart.begin(since_last=job.SINCE_UPDATE),
242
+ safe_print(''.join([chart.begin(since_last=interval),
243
dimension_updated,
244
variables_updated,
245
'END\n']))