Tutorials / Tech blog / Geek Zone

Latest Posts

Spring Boot :: Actuator

In this tutorial we are going to learn about Sprint Boot Actuators. We will also glance upon few basic ways to implement these Actuators in our production projects.

What is Spring Boot Actuator

Spring Boot Actuator provides several out of the box production grade services for our applications.It includes a number of additional features to help you monitor and manage your application when it’s pushed to production. You can choose to manage and monitor your application using HTTP endpoints, with JMX or even by remote shell (SSH or Telnet). Auditing, health and metrics gathering can be automatically applied to your application. The user guide covers more in-depth details around these features.

Once Actuators are configured in your project, it provides 16 in-built endpoints to monitor and manage your application. It also allows you to create custom endpoints of our own or modify existing ones. As these endpoints provide crucial information about the production services, it is obivious that these cannot be exposed publicly. Spring Boot provides sensitive defaults to true to all endpoints except /info and /health which requires proper authentication / authorization .   

How to enable Spring Boot Actuator

Adding the following actuator dependency to POM.xml will do the trick for us.

Some of the most common endpoints are as follows:
  • /health - Shows application health information (when the application is secure, a simple ‘status’ when accessed over an unauthenticated connection or full message details when authenticated). It is not sensitive by default.
  • /info - Displays arbitrary application info. It is not sensitive by default.
  • /metrics - Shows metric information for the current application. Sensitive by default.
  • /trace - Displays trace information (by default the last 100 HTTP requests). Sensitive by default.

More details around other endpoints can be found on the official documentation page

Customize Endpoints

Each endpoint can be customized via application.properties file using Spring properties. They adhere to the following format:

endpoints.[endpoints name].[property to customize]

The following are the properties made available for customizations
  • idname by which this endpoint will be accessed over HTTP
  • enabled – if set true, then it can be accessed otherwise not
  • sensitive – if set true, then it needs relevant authorization to render crucial information over HTTP

Let's customize /info endpoint in application.properties file.

The output will be as follows:

Let's customize /metrics endpoint in application.properties file.

The output will be as follows:

No comments:

Post a Comment