Skip to content
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

Support custom JMX urls #80

Merged
merged 2 commits into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/datadog/jmxfetch/ConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static ConnectionManager getInstance() {
private static String generateKey(LinkedHashMap<String, Object> connectionParams) {
if (connectionParams.get("process_name_regex") != null) {
return (String) connectionParams.get("process_name_regex");
} else if (connectionParams.get("jmx_url") != null) {
return (String) connectionParams.get("jmx_url");
}
return connectionParams.get("host") + ":" + connectionParams.get("port") + ":" + connectionParams.get("user");
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ public Instance(LinkedHashMap<String, Object> yamlInstance, LinkedHashMap<String

// Generate an instance name that will be send as a tag with the metrics
if (this.instanceName == null) {
if (this.yaml.get("process_name_regex") == null) {
if (this.yaml.get("process_name_regex") != null) {
this.instanceName = this.checkName + "-" + this.yaml.get("process_name_regex");
} else if (this.yaml.get("host") != null) {
this.instanceName = this.checkName + "-" + this.yaml.get("host") + "-" + this.yaml.get("port");
} else {
this.instanceName = this.checkName + "-" + this.yaml.get("process_name_regex");
LOGGER.warn("Cannot determine a unique instance name. Please define a name in your instance configuration");
this.instanceName = this.checkName;
}
}

Expand Down Expand Up @@ -123,6 +126,8 @@ public void init(boolean forceNewConnection) throws IOException, FailedLoginExce
public String toString() {
if (this.yaml.get("process_name_regex") != null) {
return "process_regex: " + this.yaml.get("process_name_regex");
} else if (this.yaml.get("jmx_url") != null) {
return (String) this.yaml.get("jmx_url");
} else {
return this.yaml.get("host") + ":" + this.yaml.get("port");
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/datadog/jmxfetch/RemoteConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class RemoteConnection extends Connection {
private String user;
private String password;
private String path = "jmxrmi";
private String jmx_url;
private static final String TRUST_STORE_PATH_KEY = "trust_store_path";
private static final String TRUST_STORE_PASSWORD_KEY = "trust_store_password";
private final static Logger LOGGER = Logger.getLogger(Connection.class.getName());
Expand All @@ -27,12 +28,13 @@ public RemoteConnection(LinkedHashMap<String, Object> connectionParams)
port = (Integer) connectionParams.get("port");
user = (String) connectionParams.get("user");
password = (String) connectionParams.get("password");
jmx_url = (String) connectionParams.get("jmx_url");
if (connectionParams.containsKey("path")){
path = (String) connectionParams.get("path");
}
env = getEnv(connectionParams);
address = getAddress(connectionParams);

String trustStorePath;
String trustStorePassword;
if (connectionParams.containsKey(TRUST_STORE_PATH_KEY)
Expand All @@ -42,7 +44,7 @@ public RemoteConnection(LinkedHashMap<String, Object> connectionParams)
if (trustStorePath != null && trustStorePassword != null) {
System.setProperty("javax.net.ssl.trustStore", trustStorePath);
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);

LOGGER.info("Setting trustStore path: " + trustStorePath + " and trustStorePassword");
}

Expand All @@ -61,7 +63,10 @@ private HashMap<String, Object> getEnv(

private JMXServiceURL getAddress(
LinkedHashMap<String, Object> connectionParams) throws MalformedURLException {
return new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + this.host + ":" + this.port +"/" + this.path);
if (this.jmx_url != null) {
return new JMXServiceURL(this.jmx_url);
}
return new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + this.host + ":" + this.port +"/" + this.path);
}


Expand Down