From aec4f100eeb8f2ea3c0c0c0c42f26b103dbec3c7 Mon Sep 17 00:00:00 2001 From: Yoav Date: Tue, 11 Feb 2014 11:07:27 +0000 Subject: [PATCH] better handling of intervals * reducing the actual processing time from the interval, so it runs in more accurate intervals independent of the processing time. * if processing time takes longer than the interval, we run it instantly --- m2g-poller.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/m2g-poller.py b/m2g-poller.py index ebc0e48..46a50ab 100755 --- a/m2g-poller.py +++ b/m2g-poller.py @@ -35,12 +35,14 @@ class Munin(): """Bootstrap method to start processing hosts's Munin stats.""" self.connect() self.update_hostname() - self.process_host_stats() + processing_time = self.process_host_stats() + interval = self.args.interval - while True and self.args.interval != 0: - time.sleep(self.args.interval) + while True and interval != 0: + sleep_time = max(interval - processing_time, 0) + time.sleep(sleep_time) self.connect() - self.process_host_stats() + processing_time = self.process_host_stats() def update_hostname(self): """Updating hostname from connection hello string.""" @@ -183,6 +185,7 @@ class Munin(): self.close_connection() logging.info("Finished querying host %s (Execution Time: %.2f sec).", self.hostname, end_timestamp) + return end_timestamp def send_to_carbon(self, timestamp, plugin_name, plugin_config, plugin_data): """Send plugin data to Carbon over Pickle format."""