6

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?

Peter Hall
  • 53,120
  • 14
  • 139
  • 204
Divs
  • 1,578
  • 2
  • 24
  • 51

1 Answers1

2

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);
   }
ngeek
  • 7,733
  • 11
  • 36
  • 42