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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With