Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export Spring Boot Actuator Metrics using Dropwizard to Jmx or Graphite

I want to use Spring Boot MetricsWriter to write/export data from my Spring Boot application to a data source of my choice (say - Jmx/Graphite). I can use JmxReporter/GraphiteReporter, but I guess Spring's abstraction of Writer/Exporter can play a vital role in terms of data source changes later.

My REST endpoint is annotated with Dropwizard annotations

@Timed(absolute=true, name="invokeEndpoint")
public ResponseEntity<Object> callSomeApi() {
   ...
}

My configuration class looks like this:

@Configuration
public class SpringBootMetrics {

    @Bean
    @ExportMetricReader
    public MetricReader metricReader() {
        return new MetricRegistryMetricReader(metricRegistry());
    }   

    public MetricRegistry metricRegistry() {
        final MetricRegistry metricRegistry = new MetricRegistry();
        return metricRegistry;
    }

    @Bean
    @ExportMetricWriter
    MetricWriter metricWriter(MBeanExporter exporter) {
        return new JmxMetricWriter(exporter);
    }
}

I don't see any metrics for endpoint invocation to be collected in Jmx through my jconsole. What am I missing?

like image 281
Divs Avatar asked May 06 '17 12:05

Divs


1 Answers

The only missing piece in this case seems to be to add a org.springframework.boot.actuate.endpoint.MetricsEndpointMetricReader to your Spring configuration, like for example:

   @Bean
   MetricsEndpointMetricReader metricsEndpointMetricReader(MetricsEndpoint metricsEndpoint) {
      return new MetricsEndpointMetricReader(metricsEndpoint);
   }
like image 112
ngeek Avatar answered Sep 30 '22 07:09

ngeek