Skip to content

Commit

Permalink
IHOST-1609 added remoting-jmx url connection format
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranorriols committed Mar 14, 2019
1 parent b5a52ac commit c019eef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/org/newrelic/nrjmx/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public static void main(String[] args) {
cliArgs.getHostname(), cliArgs.getPort(),
cliArgs.getUsername(), cliArgs.getPassword(),
cliArgs.getKeyStore(), cliArgs.getKeyStorePassword(),
cliArgs.getTrustStore(), cliArgs.getTrustStorePassword()
cliArgs.getTrustStore(), cliArgs.getTrustStorePassword(),
cliArgs.getIsRemoteJMX()
);
} catch (ConnectionError e) {
logger.severe(e.getMessage());
Expand Down
9 changes: 9 additions & 0 deletions src/org/newrelic/nrjmx/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Arguments {
private String trustStorePassword;
private boolean verbose;
private boolean debug;
private boolean isRemoteJMX;


Arguments(String[] args) {
Expand Down Expand Up @@ -59,6 +60,9 @@ public class Arguments {
Option help = Option.builder("h")
.longOpt("help").desc("Show help").hasArg(false).build();
options.addOption(help);
Option remote = Option.builder("r")
.longOpt("remote").desc("Remote JMX mode").hasArg(false).build();
options.addOption(remote);

HelpFormatter formatter = new HelpFormatter();
CommandLineParser parser = new DefaultParser();
Expand Down Expand Up @@ -87,6 +91,7 @@ public class Arguments {
this.trustStorePassword = cmd.getOptionValue("trustStorePassword", "");
this.verbose = cmd.hasOption("verbose");
this.debug = cmd.hasOption("debug");
this.isRemoteJMX = cmd.hasOption("remote");
}

public String getHostname() {
Expand All @@ -101,6 +106,10 @@ public String getUsername() {
return username;
}

public Boolean getIsRemoteJMX() {
return isRemoteJMX;
}

public String getPassword() {
return password;
}
Expand Down
6 changes: 5 additions & 1 deletion src/org/newrelic/nrjmx/JMXFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ public class ValueError extends Exception {
public ValueError(String message) { super(message); }
};

public JMXFetcher(String hostname, int port, String username, String password , String keyStore, String keyStorePassword, String trustStore, String trustStorePassword) throws ConnectionError {
public JMXFetcher(String hostname, int port, String username, String password , String keyStore, String keyStorePassword, String trustStore, String trustStorePassword, Boolean isRemote) throws ConnectionError {
String connectionString = String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", hostname, port);
if (isRemote) {
connectionString = String.format("service:jmx:remoting-jmx://%s:%s", hostname, port);
}

Map<String, String[]> env = new HashMap<>();
if (username != "") {
env.put(JMXConnector.CREDENTIALS, new String[] { username, password });
Expand Down

0 comments on commit c019eef

Please sign in to comment.