A Guide to Monitoring APIs with Spring Boot Actuator

Damith Neranjan Samarakoon
Geek Culture
Published in
3 min readMar 6, 2023
Photo by Growtika on Unsplash

Before push your application in to production , need to manage and monitor your applications. For that Spring Boot provides many features that make easier to keep an Application monitoring and alive.

The spring-boot-actuator module provides all of Spring Boot’s production-ready features. Spring boot creating a library which can export REST endpoints , then different monitoring tools used that REST endpoints and get the data out of the REST endpoints. That is why spring actuator are created. In Actuator we can use HTTP and JMX endpoints for managing and monitoring Application.

In this post , I’ll show you how you can enable actuator and use actuator endpoints.

Enabling Spring Boot Actuator to an existing application

To enable the actuator to a project , add the following ‘starter’ dependency.

for MAVEN pom.xml
for Gradle build.gradle

You can do the same through Spring Initializr, just make sure to add the Spring Boot Actuator dependency. Once all project setup done, you’re ready to go.

Once you have added the necessary dependencies, you can enable Actuator by adding the following configuration in your application.properties file:

management.endpoints.web.exposure.include=*

This will expose all the endpoints available in Spring Boot Actuator. If you want to expose only a few of them, you can do so by specifying them in the same property:

management.endpoints.web.exposure.include=health,info

This will only expose the health and info endpoints. You can also exclude certain endpoints by using the

management.endpoints.web.exposure.exclude=property.

Now that Actuator is enabled, you can start using its endpoints to monitor and manage your application.

Here are a few examples:

/actuator/health: This endpoint provides information about the health of your application. It returns a JSON response with details about the status of various components of your application.

/actuator/info: This endpoint provides general information about your application. You can use this endpoint to display things like the version number of your application.

/actuator/metrics: This endpoint provides metrics about your application, such as the number of requests processed and the average response time.

/actuator/loggers: This endpoint allows you to manage the loggers in your application. You can use this endpoint to change the logging level of specific loggers or to add new loggers.

/actuator/trace: This endpoint provides a detailed trace of HTTP requests that have been processed by your application. This can be useful for debugging purposes.

These are just a few examples of the endpoints that are available in Spring Boot Actuator. There are many more endpoints that you can use to monitor and manage your application.

In addition to the endpoints provided by Actuator, you can also create your own custom endpoints. This can be done by creating a class that implements the Endpoint interface and then registering it with Actuator. This allows you to expose custom data or functionality through an endpoint that can be accessed via a RESTful API.

In conclusion, Spring Boot Actuator provides a powerful set of tools for monitoring and managing your application. By enabling Actuator and using its endpoints, you can easily monitor the health of your application, gather metrics, manage loggers, and more. And if the endpoints provided by Actuator are not sufficient, you can create your own custom endpoints to expose additional functionality.

Thanks for reading..!!

--

--

Damith Neranjan Samarakoon
Geek Culture

I’m an Engineering Lead @Persistent System, blogger,thinker, husband & father of “little angle”. passionate about Technology,Engineering and Learning.