I would like to know if exist some way to disable the monitoring of a Specific DataSource by SpringBoot Actuator.
Scenario: One Microservice uses 3 Datasources but for some Business Reason, one Datasource of them, it is not necessary to be monitored by Spring Boot Health Indicator.
How to disable the monitoring of one specific DataSource?
Many thanks in advance
Juan Antonio
To monitor the availability of your microservices, orchestrators like Kubernetes and Service Fabric periodically perform health checks by sending requests to test the microservices. When an orchestrator determines that a service/container is unhealthy, it stops routing requests to that instance.
You can enable or disable an actuator endpoint by setting the property management. endpoint. <id>. enabled to true or false (where id is the identifier for the endpoint).
To show health check status on the dashboard, you have to configure through the HealthCheck-UI settings. Name: Name of the service which implements the Health Check API. Uri: The endpoint which provides health check data. HealthChecks: The collection of health checks URIs to evaluate.
I think you'd have to disable the default datasources health indicator, which you can do with this property:
management.health.db.enabled=false
And then configure your own health indicators which only address the datasources you are interested in, something like this perhaps:
@Autowired
private DataSource dataSourceA;
@Autowired
private DataSource dataSourceB;
@Bean
public DataSourceHealthIndicator dataSourceHealthIndicatorA() {
return new DataSourceHealthIndicator(dataSourceA);
}
@Bean
public DataSourceHealthIndicator dataSourceHealthIndicatorB() {
return new DataSourceHealthIndicator(dataSourceB);
}
Or, alternatively write your own 'multiple datasources health indicator' by extending AbstractHealthIndicator
and injecting into it only the Datasources
you are interested in monitoring. Any Spring bean of type HealthIndicator
will be automatically registered with the health
actuator so you only have to let Spring create your custom HealthIndicator
and it will be exposed by the actuator.
For background, you can see how Spring configures the default datasource health check in: org.springframework.boot.actuate.autoconfigure.DataSourcesHealthIndicatorConfiguration
.
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