I'm using spring-boot-starter-actuator
for getting a localhost/metrics
endpoint.
Now I also want to use the dropwizard.metrics
and the metrics-servlets
dependency. On their webpage (https://dropwizard.github.io/metrics/3.1.0/getting-started/) it is stated that with this a AdminServet
with some kind of admin menu for metrics, healt, threaddump and ping would be created.
But I don't see that servlet. Do I maybe have to register it explicit within spring-boot?
Of the available Dropwizard integrations, Spring support is also included.
The bare bone spring boot app starts in 1.64 seconds whereas the bare bone Dropwizard app took 1.526 seconds to startup. Spring Boot consumes much more memory. This was true. Spring Boot loaded 7591 classes whereas Dropwizard loaded 6255 classes.
Metrics is a Java library which gives you unparalleled insight into what your code does in production. Metrics provides a powerful toolkit of ways to measure the behavior of critical components in your production environment.
Web MVC and Annotation-Based WebFlux The interceptors need to be enabled for every request handler or controller that you want to time. Add @Timed to: A controller class to enable timings on every request handler in the controller.
I had to instantiate the servlet explicit and provide a servlet mapping path as follows:
@Bean
public ServletRegistrationBean servletRegistrationBean(){
return new ServletRegistrationBean(new AdminServlet(),"/metrics/admin/*");
}
In case someone is working with version 5.0.0, these steps were required to get it work:
@Inject
private ServletContext servletContext;
@Inject
private MetricRegistry metricRegistry;
@Inject
private HealthCheckRegistry healthCheckRegistry;
@Bean
public ServletRegistrationBean<Servlet> servletRegistrationBean(){
servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY,
metricRegistry);
servletContext.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY,
healthCheckRegistry);
return new ServletRegistrationBean<>(new AdminServlet(), "/metrics/*");
}
Source: https://stackoverflow.com/a/41382649/1047418
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