Reputation: 29
I need to change frequency to check DB health in springboot actuator.Default DB health check query gets executed in every millisecond. i want to make this query to be executed after every 1 min instead of in milliseconds. Is there any way to customize it?
Upvotes: 1
Views: 5714
Reputation: 51
Actually actuator only executes when you consumed the api. If you want your actuator updated, you can do two things first is to call the api every minute, another one is to create a custom health check and enable scheduling.
@SpringBootApplication
@EnableScheduling
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication .class, args);
}
}
@Service
public class CustomService {
@Scheduled(fixedDelay = 60000)
public Object getResultFromQuery() {
// call your query
}
}
@Component
public class HealthCustomCheck implements HealthIndicator {
private final CustomService customService;
public HealthCustomCheck(CustomService customService) {
this.customService = customService;
}
@Override
public Health health() {
return Health.up().withDetail("yourQuery", customService.getResultFromQuery().toString()).build();
}
}
Upvotes: 3