package com.github.lookout.metrics.agent;

import com.timgroup.statsd.NonBlockingStatsDClient;
import com.timgroup.statsd.StatsDClient;

import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;

public class ReportAgent {
    public static void premain(final String agentArgs, final Instrumentation inst) throws IOException {
        String host;
        try {
            host = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            host = "unknown-host";
        }

        for (final String reportingHostPort : agentArgs.split(",")) {
            final HostPortInterval hostPortInterval = new HostPortInterval(reportingHostPort);
            final StatsDClient client = new NonBlockingStatsDClient(host, hostPortInterval.getHost(), hostPortInterval.getPort());
            final StatsdReporter reporter = new StatsdReporter(hostPortInterval, client);
            reporter.start(hostPortInterval.getInterval(), TimeUnit.SECONDS);
        }
    }

    public static void main(final String[] args) {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // impossible
        }
    }
}


@@ -637,13 +637,8 @@
     
-for (
 fina
@@ -645,16 +645,18 @@
 l String
+%5B%5D
  reporti
@@ -669,31 +669,141 @@
 Port
- : agentArgs.split(%22,%22)
+s = (agentArgs != null) ? agentArgs.split(%22,%22) : new String%5B%5D%7Bnull%7D;%0A        for (final String reportingHostPort : reportingHostPorts
 ) %7B%0A

Fix the agent not starting if args are not supplied