Spring Boot Actuator: A Powerful Tool for Monitoring and Management

Spring Boot Actuator is a sub-project of Spring Boot that provides a set of production-ready features to help you monitor and manage your Spring Boot applications. It adds several HTTP endpoints to your application, allowing you to gain insights into its health, metrics, and other operational information.

Key Features and Benefits:

  • Health Endpoint:
  • Provides information about the overall health of your application.
  • Helps identify potential issues and proactively address them.
  • Metrics Endpoint:
  • Exposes various metrics like HTTP requests, database connections, and memory usage.
  • Enables performance monitoring and optimization.
  • Info Endpoint:
  • Displays information about the application, such as version, build time, and configuration properties.
  • Environment Endpoint:
  • Reveals the environment variables and properties used by the application.
  • Beans Endpoint:
  • Lists all the beans defined in the application context.
  • Trace Endpoint:
  • Provides insights into the execution of HTTP requests, including timing information and logs.
  • Loggers Endpoint:
  • Allows you to dynamically change the logging levels of different loggers.
  • Shutdown Endpoint:
  • Provides a controlled way to shut down the application.

How to Use Spring Boot Actuator:

  1. Add the Dependency:
    Include the spring-boot-starter-actuator dependency in your pom.xml or build.gradle file.
  2. Start the Application:
    Run your Spring Boot application as usual.
  3. Access the Endpoints:
    The actuator endpoints are typically exposed at the /actuator endpoint. You can access them using a web browser or tools like curl.

Security Considerations:

By default, all actuator endpoints are exposed publicly. For production environments, it’s crucial to secure these endpoints. You can:

  • Enable Basic Authentication:
    Configure basic authentication to protect sensitive endpoints.
  • Use Spring Security:
    Integrate Spring Security to control access to actuator endpoints based on user roles and permissions.

Customization and Extension:

You can customize actuator endpoints and add custom endpoints to expose specific information about your application. This allows you to tailor the monitoring and management capabilities to your specific needs.

Spring Boot Actuator is a valuable tool for gaining visibility into your Spring Boot applications. By leveraging its powerful features, you can proactively monitor, troubleshoot, and optimize your applications, ensuring optimal performance and reliability.

By default only ‘/health’ endpoint is exposed

So , we can add below properties in Application.properties file

management.endpoints.web.exposure.include=*
management.info.env.enabled = true

Add below dependency in pom.xml

                <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

if you are running spring boot project in local 8080 port :

http://localhost:8080/actuator/threaddump

http://localhost:8080/actuator/mappings

http://localhost:8080/actuator/beans – this endpoint will give all beans

http://localhost:8080/actuator/health – this endpoint will give output as below :

{
  "status": "UP"
}

You have to enable management.info.env.enabled true and you can add any kind of details that you want inside of the property file. like below. and make sure to enable info for web.exposure. all the configurations are like below.

management.endpoints.web.exposure.include=health,info
management.info.env.enabled = true

#management.endpoints.web.exposure.include=*

after adding above properties if you want to display any custom properties for info endpoint then you can add as below in properties file:

management.endpoints.web.exposure.include=health,info
#management.endpoints.web.exposure.include=*
management.info.env.enabled = true


#custom properties for info
info.app.name=mycoolapp
info.app.description=learning app
info.app.version=1.0

now if you access info enpoint as below :

http://localhost:8080/actuator/info

{
  "app": {
    "name": "mycoolapp",
    "description": "learning app",
    "version": "1.0"
  }
}

Happy Learning..

Leave a Reply

Your email address will not be published. Required fields are marked *