package io.prometheus.jmx;

import java.io.File;
import java.lang.instrument.Instrumentation;
import java.net.InetSocketAddress;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.hotspot.DefaultExports;

public class JavaAgent {

   static HTTPServer server;

   public static void premain(String agentArgument, Instrumentation instrumentation) throws Exception {
     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>");
       System.exit(1);
     }

     int port;
     String file;
     InetSocketAddress socket;

     if (args.length == 3) {
       port = Integer.parseInt(args[1]);
       socket = new InetSocketAddress(args[0], port);
       file = args[2];
     } else {
       port = Integer.parseInt(args[0]);
       socket = new InetSocketAddress(port);
       file = args[1];
     }

     new JmxCollector(new File(file)).register();
     DefaultExports.initialize();
     server = new HTTPServer(socket, CollectorRegistry.defaultRegistry, true);
   }
}

@@ -432,16 +432,546 @@
 ption %7B%0A
+     // Bind to all interfaces by default (this includes IPv6).%0A     String host = %220.0.0.0%22;%0A%0A     // If we have IPv6 address in square brackets, extract it first and then%0A     // remove it from arguments to prevent confusion from too namy colons.%0A     Integer indexOfClosingSquareBracket = agentArgument.indexOf(%22%5D:%22);%0A     if (indexOfClosingSquareBracket %3E= 0) %7B%0A       host = agentArgument.substring(0, indexOfClosingSquareBracket + 1);%0A       agentArgument = agentArgument.substring(indexOfClosingSquareBracket + 2);%0A     %7D%0A%0A
      Str
@@ -1503,16 +1503,22 @@
 Address(
+host, 
 port);%0A 

Support for IPv6 bind (#222)