diff --git a/agent.py b/agent.py index b6edb1768b..e26cf73349 100755 --- a/agent.py +++ b/agent.py @@ -48,7 +48,7 @@ ) from daemon import AgentSupervisor, Daemon from emitter import http_emitter -from jmxfetch import get_jmx_checks +from jmxfetch import get_jmx_checks, JMXFetch # utils from utils.cloud_metadata import EC2 @@ -103,6 +103,7 @@ def __init__(self, pidfile, autorestart, start_event=True, in_developer_mode=Fal self.sd_backend = None self.supervisor_proxy = None self.sd_pipe = None + self.last_jmx_piped = None def _handle_sigterm(self, signum, frame): """Handles SIGTERM and SIGINT, which gracefully stops the agent.""" @@ -342,6 +343,12 @@ 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 + 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 Exception as e: log.warn('Something went wrong while looking for config template changes: %s' % str(e)) @@ -454,6 +461,7 @@ def _submit_jmx_service_discovery(self, jmx_sd_configs): # JMX will unblock when it reads on the other end. os.write(self.sd_pipe, buffer) os.write(self.sd_pipe, SD_CONFIG_TERM) + self.last_jmx_piped = time.time() except Exception as e: log.exception("unable to submit YAML via pipe: %s", e) else: diff --git a/jmxfetch.py b/jmxfetch.py index f44b707339..bc9622c4ce 100644 --- a/jmxfetch.py +++ b/jmxfetch.py @@ -70,6 +70,8 @@ 'list_limited_attributes': "List attributes that do match one of your instances configuration but that are not being collected because it would exceed the number of metrics that can be collected", JMX_COLLECT_COMMAND: "Start the collection of metrics based on your current configuration and display them in the console"} +JMX_LAUNCH_FILE = 'jmx.launch' + LINK_TO_DOC = "See http://docs.datadoghq.com/integrations/java/ for more information" @@ -336,6 +338,16 @@ def _start(self, path_to_java, java_run_opts, jmx_checks, command, reporter, too log.exception("Couldn't launch JMXFetch") raise + @staticmethod + def _get_jmx_launchtime(): + fpath = os.path.join(get_jmx_pipe_path(), JMX_LAUNCH_FILE) + try: + _stat = os.stat(fpath) + except OSError as e: + raise e + + return _stat.st_atime + @staticmethod def _is_jmx_check(check_config, check_name, checks_list): init_config = check_config.get('init_config', {}) or {}