-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flare] Add JMXFetch-specific info #1726
Conversation
8e5f156
to
b507c0b
Compare
if os.path.exists(temp_path): | ||
os.remove(temp_path) | ||
backup_out, backup_err = sys.stdout, sys.stderr | ||
backup_handlers = logging.root.handlers[:] | ||
out, err = StringIO.StringIO(), StringIO.StringIO() | ||
if logger_name: | ||
# If specified, redirect logger output to `out` | ||
logger = logging.getLogger(logger_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you send the output of jmxfetch to stdout
(https://github.com/DataDog/dd-agent/pull/1726/files#diff-64a477c26f008c29252aad6c1499c099R283), do you still need this ? I guess it's for jmxfetch.py
, what does it log ? (I have no idea, just asking)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for jmxfetch.py
indeed, it logs exceptions that occur, problems with configuration files, and the exact command that is used to launch JMXFetch (which includes the java bin path and JVM options)
Watchdog, | ||
) | ||
from utils.flare import configcheck, Flare | ||
from utils.jmx_command import jmx_command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for the cleanup !
Maybe we should merge utils.jmx_command
and utils.jmxfiles
to have only a single JMX util
package. What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, that makes a lot of sense, I'll regroup them in one utils.jmx
module ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm actually I get circular imports when the two are merged together, as jmxfetch
imports utils.jmx
(for the JMXFiles
class) that itself imports jmxfetch
(for the JMXFetch
class used by jmx_command
).
So unless there's a better solution I'll leave the two modules separated for now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing JMXFetch
in the scope of the method only, would prevent this:
def jmx_command()
from jmxfetch import JMX_LIST_COMMANDS, JMXFetch
...
Another great feature, that will make support way easier. Thanks @olivielpeau. Can you attach an example of a flare archive to have an idea of what it looks like ? |
b507c0b
to
7047f84
Compare
The command output is saved in an arbitrarily-named temp file
7733c03
to
378fdae
Compare
Thanks a lot for your reviews @yannmh and @degemer! I've added two commits that:
And here is an example flare archive: https://www.dropbox.com/s/orjuu2kbn9d1aol/datadog-agent-2015-06-30-15-03-16.tar.bz2?dl=0 |
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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicky: we are also adding the output of JMXFetch.get_configuration(get_confd_path())
to java_version.log
. Is it intended ?
>>>> STDOUT <<<<
tomcat check does not have a valid JMX configuration: You need to have at least one instance defined in the YAML file for this check
Popen(['java', '-version'], stderr = -2, stdout = -1) called
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
>>>> STDERR <<<<
Maybe we could drop it and add a >>>> CMD <<<<
section to _add_command_output_tar
with the actual command printed (in this case it's interesting as it may contains a custom java path).
Looks great @olivielpeau. Let's merge it whenever you want. |
- extract JMXFetch setup and launch from agent.py to a separate module to allow JMXFetch call from flare - put all jmx utils (ie JMXFiles and the new jmx_command) in a single utils.jmx module
- To make it easier to get JMXFetch's configuration from flare, `get_configuration` becomes a classmethod that calls `_is_jmx_check` as a staticmethod - For more consistency, `check_list` is renamed to `checks_list`
The user should not see any output from the called commands. In `check_status.py`, stop assuming that all streams have a `name` attribute (for instance `StringIO.StringIO` instances do not have one).
The output/loggers capturing logic has been extracted in a separate method to allow retrieving the returned value of the command (useful here to get the value `jmx_process.shoud_run()`)
5660d86
to
a4dd433
Compare
Thanks @yannmh for your very good points ;) I've merged Now commands can also have an optional description.
|
from config import _windows_commondata_path | ||
from util import yDumper | ||
from config import _windows_commondata_path, get_confd_path | ||
from util import get_os, yDumper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this import ? (get_os
) If get_confd_path
doesn't have a get_os()
, it will call it itself, so it's no necessary.
These exceptions are output either to stderr or to the returned err stream
Also remove the output of JMXFetch.get_configuration as it is redundant
Removed it as get_confd_path calls get_os on its own.
a4dd433
to
3ce28db
Compare
Thanks again @degemer! I've changed the
|
[flare] Fix typo is not going to work as a commit short desc. |
`ouput` --> `output`
3ce28db
to
4981b5a
Compare
Haha, I guess I got lazy on this one, I've fixed it, thanks! Will merge as soon as the ci passes. |
[flare] Add JMXFetch-specific info
Adds in a
jmxinfo
directory:jmx_status.yaml
andjmx_status_python.yaml
list_matching_attributes
andlist_everything
java -version
output (using the configured java path) in ajava_version.log
file@remh One thing that may not work properly in flare is the change I've made here https://github.com/DataDog/dd-agent/compare/olivielpeau/jmx-flare?expand=1#diff-64a477c26f008c29252aad6c1499c099R271 , which basically leaves file descriptors open (
close_fds=False
) when the JMXFetch subprocess is launched from the flare command. Do you know what issues can happen when the main process leaves the file descriptors open ?cc @degemer @yannmh