Disable spring boot actuator endpoints java config
Asked Answered
I

2

14

I woud like to disable all actuator endpoints except for the health endpoint. All docs describe how to achieve this in the resource properties:

endpoints.enabled=false
endpoints.health.enabled=true

but I have always preferred to use inline java configuration. Could someone please explain where in the application I can configure the same?

Illinois answered 10/7, 2015 at 9:9 Comment(0)
P
3

Looking at org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration, the endpoints are provided when the beans are missing. One option would be to provide them in your own configuration class. All endpoints have the field enabled. You could provide all of them, setting enabled on false, except for the one you need.

@Configuration
public class ActuatorConfiguration {

    @Autowired(required = false)
    private Collection<PublicMetrics> publicMetrics;

    @Bean
    public MetricsEndpoint metricsEndpoint() {
        List<PublicMetrics> publicMetrics = new ArrayList<>();
        if (this.publicMetrics != null) {
            publicMetrics.addAll(this.publicMetrics);
        }
        Collections.sort(publicMetrics,AnnotationAwareOrderComparator.INSTANCE);
        MetricsEndpoint metricsEndpoint = new MetricsEndpoint(publicMetrics);
        metricsEndpoint.setEnabled(false);
        return metricsEndpoint;
    }
}
Pournaras answered 10/7, 2015 at 10:49 Comment(2)
Are you able to give example of a sample bean that disables an endpoint?Illinois
edited my answer to give an example on how to disable the metricsendpoind. In the EndpointAutoConfiguration endpoint you can find all the other ones you could disable by .setEnabled(false)Pournaras
T
1

I found this question, wanted to post an update from / a reference to the current docs

I guess what you want to do would be something like this these days:

management.endpoints.jmx.exposure.exclude=*
management.endpoints.web.exposure.include=health

https://docs.spring.io/spring-boot/docs/2.6.4/reference/htmlsingle/#actuator.endpoints.exposing

Trella answered 23/3, 2022 at 19:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.