package pl.java.scalatech.metrics;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.graphite.Graphite;
import com.codahale.metrics.graphite.GraphiteReporter;
import com.ryantenney.metrics.spring.config.annotation.EnableMetrics;
import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter;

import lombok.extern.slf4j.Slf4j;
@Configuration
@ConditionalOnProperty(name = {
        "metrics.graphite.host",
        "metrics.graphite.port",
        "metrics.graphite.prefix"}
)
@Slf4j
@EnableMetrics
public class GraphiteConfig extends MetricsConfigurerAdapter  {
    @Autowired
    private MetricRegistry metricRegistry;
    @Value("${metrics.graphite.host}")
    private String host;
    @Value("${metrics.graphite.port}")
    private int port;
    @Value("${metrics.graphite.prefix}")
    private String prefix;
    
    @PostConstruct
    public void startGraphiteReporter() throws UnknownHostException {
        log.info("+++ graphite metrics enabled ");
        String hostname = InetAddress.getLocalHost().getHostName();

        Graphite graphite = new Graphite(host,port);
        GraphiteReporter reporter = GraphiteReporter
                .forRegistry(metricRegistry)
                .prefixedWith(prefix + hostname)
                .build(graphite);
        reporter.start(10, TimeUnit.SECONDS);
    }
}

@@ -28,32 +28,39 @@
 etrics;%0A%0Aimport 
+static 
 java.net.InetAdd
@@ -63,17 +63,31 @@
 tAddress
-;
+.getLocalHost;%0A
 %0Aimport 
@@ -963,23 +963,16 @@
 Metrics%0A
-public 
 class Gr
@@ -1420,77 +1420,8 @@
 %22);%0A
-        String hostname = InetAddress.getLocalHost().getHostName();%0A%0A
     
@@ -1610,16 +1610,36 @@
 x + 
-hostn
+getLocalHost().getHostN
 ame
+()
 )%0A  

Update GraphiteConfig.java