Skip to content

Commit

Permalink
Support for IPv6 bind (#222)
Browse files Browse the repository at this point in the history
This enables bind to IPv6 address in square brackets:

```
-javaagent:/usr/share/jmx_exporter/agent.jar=[f00::123]:9097:/etc/kafka/jmx-exporter.yaml
```
  • Loading branch information
bobrik authored and brian-brazil committed Jan 1, 2018
1 parent 7d6eae8 commit f28d576
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ public class JavaAgent {
static HTTPServer server;

public static void premain(String agentArgument, Instrumentation instrumentation) throws Exception {
// Bind to all interfaces by default (this includes IPv6).
String host = "0.0.0.0";

// If we have IPv6 address in square brackets, extract it first and then
// remove it from arguments to prevent confusion from too namy colons.
Integer indexOfClosingSquareBracket = agentArgument.indexOf("]:");
if (indexOfClosingSquareBracket >= 0) {
host = agentArgument.substring(0, indexOfClosingSquareBracket + 1);
agentArgument = agentArgument.substring(indexOfClosingSquareBracket + 2);
}

String[] args = agentArgument.split(":");
if (args.length < 2 || args.length > 3) {
System.err.println("Usage: -javaagent:/path/to/JavaAgent.jar=[host:]<port>:<yaml configuration file>");
Expand All @@ -29,7 +40,7 @@ public static void premain(String agentArgument, Instrumentation instrumentation
file = args[2];
} else {
port = Integer.parseInt(args[0]);
socket = new InetSocketAddress(port);
socket = new InetSocketAddress(host, port);
file = args[1];
}

Expand Down

0 comments on commit f28d576

Please sign in to comment.