From f9676f7528d10168b2993474422536bcc181c876 Mon Sep 17 00:00:00 2001 From: Olivier Vielpeau Date: Fri, 23 Oct 2015 14:28:12 -0400 Subject: [PATCH] [jmxfetch] Check that a `name` is set when the `jmx_url` option is used --- conf.d/jmx.yaml.example | 8 +++++++- jmxfetch.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/conf.d/jmx.yaml.example b/conf.d/jmx.yaml.example index a5876ca2e7..c3e350ef36 100644 --- a/conf.d/jmx.yaml.example +++ b/conf.d/jmx.yaml.example @@ -8,9 +8,15 @@ instances: # port: 7199 # user: username # password: password - # process_name_regex: .*process_name.* # Instead of specifying a host, and port. The agent can connect using the attach api. + + # # If the agent needs to connect to a non-default JMX URL, specify it here instead of a host and a port + # # If you use this you need to specify a 'name' for the instance, below + # jmx_url: "service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath" + + # process_name_regex: .*process_name.* # Instead of specifying a host and port or jmx_url, the agent can connect using the attach api. # # This requires the JDK to be installed and the path to tools.jar to be set below. # tools_jar_path: /usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar # To be set when process_name_regex is set + # name: jmx_instance # # java_bin_path: /path/to/java # Optional, should be set if the agent cannot find your java executable # # java_options: "-Xmx200m -Xms50m" # Optional, Java JVM options diff --git a/jmxfetch.py b/jmxfetch.py index 305e71d5ba..95f6653965 100644 --- a/jmxfetch.py +++ b/jmxfetch.py @@ -352,9 +352,15 @@ def _is_jmx_check(check_config, check_name, checks_list): # Support for attach api using a process name regex proc_regex = inst.get('process_name_regex') + # Support for a custom jmx URL + jmx_url = inst.get('jmx_url') + name = inst.get('name') if proc_regex is not None: is_attach_api = True + elif jmx_url is not None: + if name is None: + raise InvalidJMXConfiguration("A name must be specified when using a jmx_url") else: if host is None: raise InvalidJMXConfiguration("A host must be specified")