6

I have several applications monitored under Spring Boot Admin. Spring Boot Admin is great at telling me if an application is up or down and other various metrics.

I would also like to know that certain URLs exposed by these applications are returning an HTTP status of 200. Specifically, I would like to send a GET request to these URLs once a day. If it receives a non 200 status from any of these, it sends an email stating which URLs are reporting non 200.

Is something that Spring Boot Admin is able to do? I know about custom HealthIndicators but not sure if it can be scheduled or if it's appropriate for this.

Just wanted to see if there is something Spring Boot Admin offers to support doing this before I build my own app to make the GET calls and send the email.

Update

The URLs are exposed as Eureka services and I'm calling services from other services via Spring Cloud OpenFeign.

Update 2

I went ahead and built my own custom application to handle this. Details follow but still interested if Spring offers something out-of-the-box to do this.

application.yml

app: serviceUrls: - "http://car-service/cars?category=sedan" - "http://truck-service/trucks" cron: "0 0 10 * * *" 

Urls are read into:

@Component @ConfigurationProperties(prefix = "app") @Getter @Setter public class ServiceUrls { private String[] serviceUrls; } 

Via cron, scheduled to run once a day:

@Component @RequiredArgsConstructor @Slf4j public class ServiceCheckRunner { private final ServiceHealth serviceHealth; @Scheduled(cron = "${cron}") public void runCheck() { serviceHealth.check(); } } 

This is the code that checks whether URLs return no errors:

@Service @RequiredArgsConstructor @Slf4j public class ServiceHealth { private final ServiceUrls serviceUrls; private final RestTemplate rest; public void check() { List<String> failedServiceUrls = new ArrayList<>(); for (String serviceUrl : serviceUrls.getServiceUrls()) { try { ResponseEntity<String> response = rest.getForEntity(serviceUrl, String.class); if (!response.getStatusCode().is2xxSuccessful()) { failedServiceUrls.add(serviceUrl); } } catch (Exception e){ failedServiceUrls.add(serviceUrl); } } // code to send an email with failedServiceUrls. } } 
7
  • you can register HealthIndicators for each of the downstream API and call /health endpoint which will return the status of each of the API in JSON format. would this solve your use-case? Commented Mar 25, 2021 at 4:30
  • @dkb Thanks for your suggestion. What are your thoughts on what would be calling the /health endpoint for each app? Spring Boot Admin? Commented Mar 25, 2021 at 18:31
  • 1
    you can refer to stackoverflow.com/q/44849568/2987755, baeldung.com/spring-boot-health-indicators, once you register health endpoint for all downstream API, then your applications /health endpoint is tied with rest of all the health checks. Commented Mar 26, 2021 at 4:02
  • Why don't you integrate downstream service(s) health in the service health check? Commented Mar 27, 2021 at 3:10
  • I could implement HealthIndicators. What would call those /health endpoints? Spring Boot Admin? If I'm building my app that calls those /health endpoints, then it doesn't seem any better than just building the custom app and calling URLs as I already have noted in the OP. Commented Mar 29, 2021 at 18:05

1 Answer 1

0

You can use Spring Boot Admin in order to send email notifications whenever a registered client changes his status from UP to OFFLINE or otherwise.

pom.xml

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> <version>2.4.0</version> </dependency> 

application.properties

spring.mail.host=smtp.example.com spring.mail.username=smtp_user spring.mail.password=smtp_password [email protected] 

But, if you really need to check client status once per day, you need to implement a custom solution.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.