Skip to content

Commit

Permalink
[auto-discovery][jmx] a jmxfetch restart should prompt AD check reload.
Browse files Browse the repository at this point in the history
  • Loading branch information
truthbk committed Jul 17, 2017
1 parent edc9d5f commit 25f7acd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions jmxfetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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 {}
Expand Down

0 comments on commit 25f7acd

Please sign in to comment.