Skip to content

Commit

Permalink
[auto-discovery][jmx] refactor to handle re-submissions in a cleaner …
Browse files Browse the repository at this point in the history
…manner.
  • Loading branch information
truthbk committed Jul 20, 2017
1 parent fd650c5 commit 6840937
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ def info(cls, verbose=None):
logging.getLogger().setLevel(logging.ERROR)
return CollectorStatus.print_latest_status(verbose=verbose)

def sd_pipe_jmx_configs(self, hostname):
jmx_sd_configs = generate_jmx_configs(self._agentConfig, hostname)
if jmx_sd_configs:
self._submit_jmx_service_discovery(jmx_sd_configs)

def run(self, config=None):
"""Main loop of the collector"""

Expand Down Expand Up @@ -259,7 +264,7 @@ def run(self, config=None):
if self._agentConfig.get('service_discovery'):
self.sd_backend = get_sd_backend(self._agentConfig)

if _is_affirmative(self._agentConfig.get('sd_jmx_enable', False)):
if self.sd_backend and _is_affirmative(self._agentConfig.get('sd_jmx_enable', False)):
pipe_path = get_jmx_pipe_path()
if Platform.is_windows():
pipe_name = pipe_path.format(pipename=SD_PIPE_NAME)
Expand All @@ -281,9 +286,7 @@ def run(self, config=None):

# Load JMX configs if available
if self._jmx_service_discovery_enabled:
jmx_sd_configs = generate_jmx_configs(self._agentConfig, hostname)
if jmx_sd_configs:
self._submit_jmx_service_discovery(jmx_sd_configs)
self.sd_pipe_jmx_configs(hostname)

# Initialize the Collector
self.collector = Collector(self._agentConfig, emitters, systemStats, hostname)
Expand Down Expand Up @@ -327,6 +330,16 @@ def run(self, config=None):
else:
self.reload_configs()

# JMXFetch restarts should prompt re-piping *all* JMX configs
if self._jmx_service_discovery_enabled and \
(not self.reload_configs_flag or isinstance(self.reload_configs_flag, set)):
try:
jmx_launch = JMXFetch._get_jmx_launchtime()
if self.last_jmx_piped and self.last_jmx_piped < jmx_launch:
self.sd_pipe_jmx_configs(hostname)
except Exception as e:
log.debug("could not stat JMX lunch file: %s", e)

# Do the work. Pass `configs_reloaded` to let the collector know if it needs to
# look for the AgentMetrics check and pop it out.
self.collector.run(checksd=self._checksd,
Expand All @@ -343,15 +356,6 @@ def run(self, config=None):
try:
self.sd_backend.reload_check_configs = get_config_store(
self._agentConfig).crawl_config_template()

# JMXFetch restarts should prompt reload
try:
jmx_launch = JMXFetch._get_jmx_launchtime()
if self.last_jmx_piped and self.last_jmx_piped < jmx_launch:
self.sd_backend.reload_check_configs = True
except OSError as e:
log.debug("could not stat JMX lunch file: %s", e)

except Exception as e:
log.warn('Something went wrong while looking for config template changes: %s' % str(e))

Expand Down

0 comments on commit 6840937

Please sign in to comment.