2

I have a spring-mvc application where I am trying to add spring boot actuator for performance metrics and other endpoints. I am not getting metrics, beans endpoint other than info and health endpoint. Can anyone please help me where I'm missed the configuration to get those endpoint? Spring version : 5.2.8.RELEASE Spring Boot actuator version : 2.4.2 Below is my code :

    @Configuration
    @EnableWebMvc
    @Import({
    ConfigurationPropertiesReportEndpointAutoConfiguration.class,
    EndpointAutoConfiguration.class,
    WebEndpointAutoConfiguration.class,
    HealthEndpointAutoConfiguration.class,
    HealthIndicatorAutoConfiguration.class,
    InfoEndpointAutoConfiguration.class,
    InfoContributorAutoConfiguration.class,
    LogFileWebEndpointAutoConfiguration.class,
    LoggersEndpointAutoConfiguration.class,
    BeansEndpointAutoConfiguration.class,
    EnvironmentEndpointAutoConfiguration.class,
    CachesEndpointAutoConfiguration.class,
    AuditEventsEndpointAutoConfiguration.class,
    MetricsAutoConfiguration.class,
    MetricsEndpointAutoConfiguration.class,
    WebMvcMetricsAutoConfiguration.class,
    ManagementWebSecurityAutoConfiguration.class,
    ManagementContextAutoConfiguration.class,
    ServletManagementContextAutoConfiguration.class,
    })
    @EnableConfigurationProperties(CorsEndpointProperties.class)
    public class ActuatorConfiguration2 {
    
    @Bean //taken from WebMvcEndpointManagementContextConfiguration.class
    public WebMvcEndpointHandlerMapping endpointHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,
       ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier 
            controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties 
        corsProperties, WebEndpointProperties webEndpointProperties,Environment environment) {
        List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
        Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
        allEndpoints.addAll(webEndpoints);
        allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
        allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
        //EndpointMapping endpointMapping = new EndpointMapping(webEndpointProperties.getBasePath());
        
        String basePath = webEndpointProperties.getBasePath(); 
        EndpointMapping endpointMapping = new EndpointMapping(basePath); 
        boolean shouldRegisterLinksMapping = StringUtils.hasText(basePath) || 
        ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT);
     
        return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
                corsProperties.toCorsConfiguration(),
                new EndpointLinksResolver(allEndpoints, webEndpointProperties.getBasePath()), 
        shouldRegisterLinksMapping);
    }

    @Bean
    public DispatcherServletPath dispatcherServletPath(){
        
            return () -> "/";
        }
   }

Default actuator endpoint url and response :

http://localhost:8090/com.springmvc.actuator.demo3/actuator/

{"_links":{"self":{"href":"http://localhost:8090/com.springmvc.actuator.demo3/actuator","templated":false},"health":{"href":"http://localhost:8090/com.springmvc.actuator.demo3/actuator/health","templated":false},"health-path":{"href":"http://localhost:8090/com.springmvc.actuator.demo3/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:8090/com.springmvc.actuator.demo3/actuator/info","templated":false}}}

what should i do for getting the other endpoints like : metrics, beans, caches etc?

Debasish Halder
  • 173
  • 3
  • 12

1 Answers1

1

info,health are the default endpoints for spring boot actuator.

Exposing endpoints

enter image description here

It seems that you did not declare endpoints on your application.properties. If so, pls try again by adding following:

// Enable everything with wildcard
management.endpoints.web.exposure.include=*

// You can also disable some of them
management.endpoints.web.exposure.exclude=jolokia,liquibase
Ali Can
  • 564
  • 3
  • 15
  • Thank you. I added properties file as per your suggestion but metrics end point is not coming. I added below EndPointConfiguration class for metrics WebMvcMetricsAutoConfiguration.class, MetricsEndpointAutoConfiguration.class For Metrics which configuration file I need to add? – Debasish Halder Feb 15 '21 at 11:46
  • Ohhh, it seems that your project is not a spring boot application. Is it true ? – Ali Can Feb 15 '21 at 12:00
  • Yes, It's not a spring boot project. It's a spring-mvc project where i'm trying to add spring boot actuator. – Debasish Halder Feb 15 '21 at 12:01
  • You may want to take a look to the following steps: [https://stackoverflow.com/questions/53009502/implement-spring-actuator-in-my-spring-mvc-app-without-adding-spring-boot](https://stackoverflow.com/questions/53009502/implement-spring-actuator-in-my-spring-mvc-app-without-adding-spring-boot). **Especially, configuration class...** – Ali Can Feb 15 '21 at 12:04
  • I gone through above link, but that example will work old-version(1.X) . package and class structure were completely changed in latest version(2.x) – Debasish Halder Feb 15 '21 at 12:10
  • Except metrics others endpoint are working fine. – Debasish Halder Feb 15 '21 at 12:39
  • 1
    Followed below link and my application is working as expected. https://stackoverflow.com/questions/58031056/problem-with-spring-actuator-metrics-without-enableautoconfiguration – Debasish Halder Feb 15 '21 at 15:02