8

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?

membersound
  • 81,582
  • 193
  • 585
  • 1,120

2 Answers2

5

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/*");
}
membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • I see the menu, but I can't see the matrices as empty from that link. However directly accessing /metrics gives the result with data. How did you bridge these two? – ravindrab Nov 23 '15 at 22:22
2

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

Torben
  • 3,805
  • 26
  • 31