Skip to content

Commit

Permalink
feat: add timer logs
Browse files Browse the repository at this point in the history
This adds logs around timers.
These can be useful to investigate issues
when data is not sent to Sumo.
  • Loading branch information
andrzej-stencel committed Dec 23, 2021
1 parent f96dcce commit 9d78219
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 1 addition & 3 deletions sumologic_collectd_metrics/metrics_batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ def __init__(self, max_batch_size, max_batch_interval, met_buffer, collectd):
Init MetricsBatcher with max_batch_size, max_batch_interval, and met_buffer
"""

Timer.__init__(self, max_batch_interval, self.flush)

self.collectd = collectd

Timer.__init__(self, max_batch_interval, self.flush)
# initiate max_batch_size and max_batch_interval
self.max_batch_size = max_batch_size
self.max_batch_interval = max_batch_interval
Expand Down
3 changes: 1 addition & 2 deletions sumologic_collectd_metrics/metrics_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def __init__(self, conf, met_buf, collectd):
Init MetricsSender with conf and met_buf
"""

Timer.__init__(self, conf[ConfigOptions.http_post_interval], self._request_scheduler)

self.collectd = collectd
Timer.__init__(self, conf[ConfigOptions.http_post_interval], self._request_scheduler)
self.conf = conf
self.buffer = met_buf
self.http_headers = self._build_header()
Expand Down
11 changes: 11 additions & 0 deletions sumologic_collectd_metrics/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def __init__(self, interval, task):
self.task = task
self.timer = None
self.start_timer_lock = threading.Lock()
self.run_count = 0
self.run_count_reset = 60 / interval
if hasattr(self, 'collectd'): self.collectd.info('Timer %s will report once a minute (every %s runs).' % (self.__class__.__name__, self.run_count_reset))

def __del__(self):
self.cancel_timer()
Expand All @@ -22,6 +25,12 @@ def start_timer(self):
Start a thread to periodically run task func
"""

if hasattr(self, 'collectd'): self.collectd.debug('Timer has been run: %s.' % self.__class__.__name__)
if (self.run_count >= self.run_count_reset):
if hasattr(self, 'collectd'): self.collectd.info('Timer %s has run %s times.' % (self.__class__.__name__, self.run_count))
self.run_count = 0
self.run_count += 1

self.timer = threading.Timer(self.interval, self.start_timer)
self.timer.daemon = True
# Lock to resolve racing condition for start_timer and reset_timer
Expand All @@ -33,9 +42,11 @@ def start_timer(self):
self.task()

def cancel_timer(self):
if hasattr(self, 'collectd'): self.collectd.debug('Timer has been canceled: %s.' % self.__class__.__name__)
if self.timer is not None:
self.timer.cancel()

def reset_timer(self):
if hasattr(self, 'collectd'): self.collectd.debug('Timer has been reset: %s' % self.__class__.__name__)
self.cancel_timer()
self.start_timer()

0 comments on commit 9d78219

Please sign in to comment.