Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable spring boot actuator endpoints java config

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?

like image 278
MarcF Avatar asked Jul 10 '15 09:07

MarcF


1 Answers

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;
    }
}
like image 184
Qkyrie Avatar answered Sep 22 '22 06:09

Qkyrie