Spring Boot Monitoring with Actuator Questions and Answers — Questions and Answers
Question 1: A developer wants to expose only the `health` and `info` Actuator endpoints over HTTP for external monitoring, while keeping all other endpoints hidden for security. Which configuration in `application.properties` achieves this?
- management.endpoints.web.exposure.exclude=*
- management.endpoints.web.exposure.include=health,info (Correct answer)
- management.endpoints.web.enabled-by-default=false management.endpoint.health.enabled=true management.endpoint.info.enabled=true
- endpoints.web.exposure=health,info
Correct answer: management.endpoints.web.exposure.include=health,info
In Spring Boot Actuator, the `management.endpoints.web.exposure.include` property is used to explicitly list the endpoint IDs that should be exposed over HTTP. By default, only `health` and `info` are exposed. To be explicit and secure, setting this property to 'health,info' ensures that only these two are accessible via the web, overriding any other defaults or broad inclusions. The `exclude` property takes precedence over `include`, so excluding '*' would hide all endpoints.
Question 2: What is the primary role of Micrometer in the context of Spring Boot Actuator?
- To provide a vendor-neutral application metrics facade. (Correct answer)
- To secure Actuator endpoints with authentication and authorization.
- To create custom health indicators for the `/health` endpoint.
- To expose Spring beans and application properties via JMX.
Correct answer: To provide a vendor-neutral application metrics facade.
Micrometer acts as a metrics collection facade, similar to how SLF4J is a facade for logging. It provides a common API to instrument application code for metrics (like timers, counters, and gauges) without tying the application to a specific monitoring system. Spring Boot Actuator uses Micrometer to gather metrics and can then export them to various systems like Prometheus, Datadog, or InfluxDB.
Question 3: An operations team needs to access Actuator endpoints on a separate, dedicated port (e.g., 9090) to simplify network firewall rules, keeping them separate from the main application port (e.g., 8080). Which property should be set in `application.properties`?
- server.management.port=9090
- actuator.port=9090
- management.server.port=9090 (Correct answer)
- server.port.management=9090
Correct answer: management.server.port=9090
The `management.server.port` property is specifically used to configure a separate HTTP port for the management endpoints provided by Actuator. This isolates management traffic from application traffic, which is a common practice for security and operational reasons. The `server.port` property configures the main application port.
Question 4: A developer needs to add a custom check to the `/actuator/health` endpoint to verify the status of a critical downstream microservice. Which of the following is the standard Spring Boot approach?
- Create a bean that implements the `HealthIndicator` interface. (Correct answer)
- Define a new `@RestController` with a path of `/actuator/health/custom`.
- Add properties prefixed with `management.health.custom.*` to `application.properties`.
- Implement the `ApplicationRunner` interface to perform the check on startup.
Correct answer: Create a bean that implements the `HealthIndicator` interface.
The standard, extensible way to add custom health checks to the `/actuator/health` endpoint is to define a Spring bean that implements the `HealthIndicator` interface. Spring Boot Actuator will automatically discover any `HealthIndicator` beans and aggregate their status into the main health endpoint's response.
Question 5: Which Actuator endpoint provides a detailed list of all Spring beans currently in the ApplicationContext, including their scope, type, and dependencies?
- /actuator/env
- /actuator/mappings
- /actuator/configprops
- /actuator/beans (Correct answer)
Correct answer: /actuator/beans
The `/actuator/beans` endpoint is designed to provide a comprehensive report of all beans configured in the Spring `ApplicationContext`. It details each bean's name, aliases, scope, type, resource location, and the other beans it depends on, making it a powerful tool for debugging dependency injection issues.
Question 6: How can a developer contribute static application metadata, such as a version number and description, to the `/actuator/info` endpoint using only the `application.properties` file?
- By setting properties prefixed with `management.info.*`
- By creating a bean that implements `InfoContributor`
- By setting properties prefixed with `info.*` (Correct answer)
- By using the `@Info` annotation on the main application class
Correct answer: By setting properties prefixed with `info.*`
Spring Boot automatically exposes any properties in `application.properties` that are prefixed with `info.*` in the response of the `/actuator/info` endpoint. For example, `info.app.version=1.0.0` will appear in the info response. While implementing an `InfoContributor` bean is another valid way to add dynamic information, using `info.*` properties is the simplest method for static data.
A developer wants to expose only the `health` and `info` Actuator endpoints over HTTP for external monitoring, while keeping all other endpoints hidden for security.
Which configuration in `application.properties` achieves this?