Actuator in Spring Boot

Avnish Kumar
JavaToDev
Published in
3 min readFeb 24, 2024

1. Introduction

Let’s take a real-life example. In a hospital, some machines are used to monitor the patient’s health metrics. These machines give us data like pulse rate or heart rate about the patient so we can monitor the health of our patient better and take the necessary actions.

Similarly in Spring Boot, Actuator focuses on monitoring and managing your Spring Boot application in a production environment. It provides a set of production-ready features to help you understand what’s happening with your application. These features are exposed as “endpoints” that can be accessed via HTTP. Actuator endpoints offer valuable insights into application health, metrics, environment properties, and more.

2. Types of Actuator endpoints:

  1. /actuator/health: Provides information about the application’s health, which is essential for monitoring and alerting.

2. /actuator/info: Offers custom application information that can be useful for debugging or displaying details about the application.

3. /actuator/metrics: Exposes various metrics about the application, including memory usage, garbage collection, and more.

4. /actuator/env: Displays environment properties, making it easy to inspect the application’s configuration.

5. /actuator/loggers: Allows you to view and modify the configuration of loggers in your application dynamically.

3. How to use Actuator in our spring boot application:

Let’s start step by step with how to add an actuator in our application and use them.

Step 1: Go to the spring-initializer and add the two dependencies Spring Web and Spring boot actuator. Now download the project and open it in your IDE.

The structure of the project looks like:

Step 2: Now create one class as SimpleController and add the simple get request.

package com.example.simpleProject.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SimpleController {

@GetMapping("/start")
public String getStart()
{
return "Your application starts";
}

}

Step 3: Now in application.properties write the configuration given below.

management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always

Step 4: Now run your application and hit the http://localhost:8080/start.

Step5: Now hit the actuator endpoint with the url http://localhost:8080/actuator

So these are simple steps to add an actuator in our spring boot application.

4. Conclusion:

We created a simple project to know how we can simply add an actuator to our application. But actuators are much more than this. In the upcoming articles, we are going to see how we can create our custom actuator and also how we can use metrics, grafana, and prometheus in our application to monitor the metrics of our application.

--

--