Adding Graphite support to Spring Boot Actuator

I made a very simple Graphite implementation of the MetricWriter interface, you can see the code in my GitHub repo spring-boot-actuator-graphite.

If you want to use it in a production environment please be aware that it does open and close a new Socket connection for each metric measurement.

Assuming you have a Spring Boot Actuator project, below is an example @Configuration class to enable writing your metrics to Graphite.

 
@Configuration
public class MonitoringConfiguration {

    @Value("${spring.metrics.export.graphite.prefix}")
    private String prefix;

    @Value("${spring.metrics.export.graphite.host}")
    private String host;

    @Value("${spring.metrics.export.graphite.port}")
    private int port;

    @Bean
    public MetricsEndpointMetricReader metricsEndpointMetricReader(MetricsEndpoint metricsEndpoint) {
        return new MetricsEndpointMetricReader(metricsEndpoint);
    }

    @Bean
    @ExportMetricWriter
    MetricWriter metricWriter() {
        return new GraphiteMetricWriter(this.prefix, this.host, this.port);
    }
}