Skip to content

Commit

Permalink
Customizable java directory, fix #472
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi Hakim committed Apr 29, 2013
1 parent 25f5f7e commit 570b226
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
19 changes: 15 additions & 4 deletions checks/jmx_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def terminate(self):

self._jmx = None

def connect(self, connection, user=None, passwd=None, timeout=20, priority=DEFAULT_PRIORITY):
def connect(self, connection, user=None, passwd=None, timeout=20,
priority=DEFAULT_PRIORITY, java_bin_path=None):

import pexpect
from pexpect import ExceptionPexpect

Expand All @@ -97,10 +99,15 @@ def connect(self, connection, user=None, passwd=None, timeout=20, priority=DEFAU
# Figure out which path to the jar, __file__ is jmx.pyc
pth = os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "libs", "jmxterm-1.0-DATADOG-uber.jar"))
# Only use nice is the requested priority warrants it


if java_bin_path is None:
java_bin_path = 'java'

if priority == DO_NOT_NICE:
cmd = "java -jar %s -l %s" % (pth, connection)
cmd = "%s -jar %s -l %s" % (java_bin_path, pth, connection)
else:
cmd = "nice -n %s java -jar %s -l %s" % (priority, pth, connection)
cmd = "nice -n %s %s -jar %s -l %s" % (priority, java_bin_path, pth, connection)
if user is not None and passwd is not None:
cmd += " -u %s -p %s" % (user, passwd)
self.log.debug("Opening JMX connector with PATH=%s" % cmd)
Expand All @@ -109,6 +116,8 @@ def connect(self, connection, user=None, passwd=None, timeout=20, priority=DEFAU
self._wait_prompt()
except ExceptionPexpect, e:
self.terminate()
if "The command was not found or was not executable" in str(e):
raise Exception("Java bin not found. You can manually set its location by using the java_bin_path parameter in the yaml config file.")
raise Exception('Error when connecting to JMX Service at address %s. JMX Connector will be relaunched.\n%s' % (connection, str(e)))

def dump_domains(self, domains, values_only=True):
Expand Down Expand Up @@ -357,6 +366,7 @@ def _load_config(self, instance):
user = instance.get('user', None)
password = instance.get('password', None)
instance_name = instance.get('name', "%s-%s-%s" % (self.name, host, port))
java_bin_path = instance.get('java_bin_path', None)

if user is not None and len(user.strip()) == 0:
user = None
Expand All @@ -382,7 +392,8 @@ def connect():
priority = int(instance.get('priority', DEFAULT_PRIORITY))
if priority < 0:
priority = 0
jmx.connect("%s:%s" % (host, port), user, password, priority=priority)
jmx.connect("%s:%s" % (host, port), user, password, priority=priority,
java_bin_path=java_bin_path)


# When the connection succeeds we set the watcher to these values that
Expand Down
1 change: 1 addition & 0 deletions conf.d/activemq.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ instances:
# user: username
# password: password
# name: activemq_instance
# #java_bin_path: /path/to/java #Optional, should be set if the agent cannot find your java executable


# List of metrics to be collected by the integration
Expand Down
1 change: 1 addition & 0 deletions conf.d/jmx.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ instances:
# name: jmx_instance
# user: username
# password: password
# #java_bin_path: /path/to/java #Optional, should be set if the agent cannot find your java executable
# conf:
# - include:
# domain: my_domain
Expand Down
2 changes: 2 additions & 0 deletions conf.d/solr.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ instances:
# user: username
# password: password
# name: solr_instance
# #java_bin_path: /path/to/java #Optional, should be set if the agent cannot find your java executable



# List of metrics to be collected by the integration
Expand Down
2 changes: 2 additions & 0 deletions conf.d/tomcat.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ instances:
# user: username
# password: password
# name: tomcat_instance
# #java_bin_path: /path/to/java #Optional, should be set if the agent cannot find your java executable


# List of metrics to be collected by the integration
# You should not need to modify this.
Expand Down

0 comments on commit 570b226

Please sign in to comment.