Skip to content

Commit

Permalink
[flare] Allow optional description of commands
Browse files Browse the repository at this point in the history
Also remove the output of JMXFetch.get_configuration as it is redundant
  • Loading branch information
olivielpeau committed Jul 1, 2015
1 parent 5c75b06 commit a4dd433
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions utils/flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def collect(self):
self._add_command_output_tar('info.log', self._info_all)
self._add_jmxinfo_tar()
log.info(" * pip freeze")
self._add_command_output_tar('freeze.log', self._pip_freeze)
self._add_command_output_tar('freeze.log', self._pip_freeze,
command_desc="pip freeze --no-cache-dir")

log.info("Saving all files to {0}".format(self._tar_path))
self._tar.close()
Expand Down Expand Up @@ -236,11 +237,12 @@ def _add_jmxinfo_tar(self):

# java version
log.info(" * java -version output")
_, _, java_bin_path = self._capture_output(
lambda: JMXFetch.get_configuration(get_confd_path())[2] or 'java')
self._add_command_output_tar(
os.path.join('jmxinfo', 'java_version.log'),
# We use lambda so that JMXFetch.get_configuration is evaluated in _add_command_output_tar,
# which captures the logging output from JMXFetch
lambda: self._java_version(JMXFetch.get_configuration(get_confd_path())[2])
lambda: self._java_version(java_bin_path),
command_desc="{0} -version".format(java_bin_path)
)

# Returns whether JMXFetch should run or not
Expand Down Expand Up @@ -302,10 +304,14 @@ def _strip_password(self, file_path):
return temp_path, password_found

# Add output of the command to the tarfile
def _add_command_output_tar(self, name, command):
def _add_command_output_tar(self, name, command, command_desc=None):
out, err, _ = self._capture_output(command)
_, temp_path = tempfile.mkstemp(prefix='dd')
with open(temp_path, 'w') as temp_file:
if command_desc:
temp_file.write(">>>> CMD <<<<\n")
temp_file.write(command_desc)
temp_file.write("\n")
temp_file.write(">>>> STDOUT <<<<\n")
temp_file.write(out.getvalue())
out.close()
Expand Down Expand Up @@ -400,7 +406,6 @@ def _jmx_command_call(self, command):

# Print java version
def _java_version(self, java_bin_path):
java_bin_path = java_bin_path or 'java'
try:
self._print_output_command([java_bin_path, '-version'])
except OSError:
Expand Down

0 comments on commit a4dd433

Please sign in to comment.