1
votes

What I want to do

  • Create two (different) endpoints using Spring Boot Actuator

My environment

  • Spring Boot 1.4.2
  • spring-boot-starter-actuator embedded in Spring Boot 1.4.2

Detail

I'm creating a Web app using Spring Boot and will need to create two separated endpoints: one for just checking application health including the app's DB connection and so on (This will be realized by the default behavior of "/health") and the other for just checking if the app is ready for accepting HTTP requests (say "/httpcheck").

To implement health check feature, I guess it's the fastest way to use Spring Boot Actuator (by default, /health is mapped to health check endpoint). I also understand we can configure this endpoint by extending AbstractHealthIndicator (so that it will include DB health check).

But as far as I could see, I could not find a way to create more than one endpoints to do different health checks. Do you have any ideas?

Thanks in advance.

2

2 Answers

1
votes

Thanks for your answer. Actually, I dealt with this problem by implementing a new endpoint (/httpcheck) to simply check if its HTTP stack works well or not.

HttpCheckEndpoint.java

@Component
@ConfigurationProperties(prefix = "endpoints.httpcheck") // Specifies the prefix on application.yml
public class HttpCheckEndpoint extends AbstractMvcEndpoint {

    public HttpCheckEndpoint() {
        super("/httpcheck", false);
    }

    /**
     * Check if simply the app can connect to their own HTTP stack and return 200 OK.
     * <ul>
     * <li>Method: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS</li>
     * <li>Endpoint: "/httpcheck"</li>
     * </ul>
     */
    @RequestMapping
    @ResponseBody
    public ResponseEntity<String> checkHttpConnecton() {
        if (!isEnabled()) {
            return new ResponseEntity<String>("", HttpStatus.NOT_FOUND);
        } else {
            return new ResponseEntity<String>("{\"status\": \"UP\"}", HttpStatus.OK);
        }
    }

}

application.yml

endpoints:
  enabled: false # Default enabled/disabled on endpoints on Spring Boot Actuator
  health: # Health check (already prepared in Spring Boot Actuator)
    enabled: true
  httpcheck: # Simple HTTP connection check (newly created by myself)
    enabled: true

I've confirmed it worked well, although not sure if it's the best solution...

0
votes

Solution

  1. You can use Jolokia end points in your Spring-boot application and get it registered with o.s.b.a.e.jmx.EndpointMBeanExporter along with your Actuator Plugins.
  2. <dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId> <version>1.2.2</version> </dependency>
  3. Jolokia Configurations in application.properties

         jolokia.config.debug=true
         endpoints.jolokia.enabled=true