Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not monitor a specific Datasource for Health Check

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

like image 965
jabrena Avatar asked Oct 14 '17 16:10

jabrena


People also ask

How do you monitor Microservices health?

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.

How do I enable health check endpoint in spring boot?

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).

How do you implement a health check?

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.


1 Answers

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.

like image 131
glytching Avatar answered Oct 03 '22 01:10

glytching