Skip to content

Commit

Permalink
Fix the wake interval issue with calling _sleep (which kicks off anot…
Browse files Browse the repository at this point in the history
…her wake interval timer)

clihelper -> helper incompatibility
  • Loading branch information
gmr committed Nov 5, 2013
1 parent 84dff82 commit 64ee518
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions newrelic_plugin_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, args, operating_system):
self._wake_interval = (self.config.application.get('wake_interval') or
self.config.application.get('poll_interval') or
self.WAKE_INTERVAL)
self.next_wake_interval = self._wake_interval
self.next_wake_interval = int(self._wake_interval)
self.publish_queue = queue.Queue()
self.threads = list()
info = tuple([__version__] + list(self.system_platform))
Expand Down Expand Up @@ -103,7 +103,7 @@ def poll_plugin(self, plugin_name, plugin, config):
'name': plugin_name,
'plugin': plugin,
'poll_interval':
self.wake_interval})
int(self._wake_interval)})
thread.run()
self.threads.append(thread)

Expand All @@ -115,17 +115,20 @@ def process(self):
"""
start_time = time.time()
self.start_plugin_polling()

# Sleep for a second while threads are running
while self.threads_running:
self._sleep()
time.sleep(1)

self.threads = list()
self.send_data_to_newrelic()
duration = time.time() - start_time
self.next_wake_interval = self._wake_interval - duration
if self.next_wake_interval < 0:
if self.next_wake_interval < 1:
LOGGER.warning('Poll interval took greater than %i seconds',
duration)
self.next_wake_interval = self._wake_interval
LOGGER.info('All stats processed in %.2f seconds, next wake in %.2f',
self.next_wake_interval = int(self._wake_interval)
LOGGER.info('Stats processed in %.2f seconds, next wake in %i seconds',
duration, self.next_wake_interval)

def process_min_max_values(self, component):
Expand Down Expand Up @@ -229,7 +232,8 @@ def send_components(self, components, metrics):
except requests.ConnectionError as error:
LOGGER.error('Error reporting stats: %s', error)

def _get_plugin(self, plugin_path):
@staticmethod
def _get_plugin(plugin_path):
"""Given a qualified class name (eg. foo.bar.Foo), return the class
:rtype: object
Expand Down

0 comments on commit 64ee518

Please sign in to comment.