Managing production environment using Spring Boot Actuator

Filipe Munhoz
3 min readMay 30, 2020

--

Spring Boot Actuator is a great tool to manage and monitor applications deployed on production environment in simple and practice way. There are a plenty of production-ready features.

The official documentation can be browsed on Spring Actuator.

Install

You can add the dependency using Maven, Gradle or Spring Initializer.

Maven

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

Spring Initializer
Search for Spring Boot Actuator

Demo

The source code is ready to download on the address below.

Git

Import

Eclipse or Sprint Tools Suite:
File -> Import -> Existing Maven Projects -> select the pom.xml

Endpoints

Most common production-ready features:

  • Health Endpoint
  • Metrics Endpoint
  • Logger Endpoint

To enable Spring Actuator features, you need to add this line on the file /src/main/resources/application.properties

management.endpoints.web.exposure.include=*

Run
Let's run the application

This is a simple webapplication that lists the most used linux distributions according distro watch.

Open the main file ActuatorDemoApplication.java, right click on that, select run as…, Spring Boot App.

Browser

Open the URL on your browser
http://localhost:8080/distro/list

JSONView

To improve the best visualization of json file on chrome, I added this plugin.

Features

Health
http://localhost:8080/actuator/health

This is a feature that shows the application health.

Metrics
Application Metris.
http://localhost:8080/actuator/metrics

Memory management

http://localhost:8080/actuator/metrics/jvm.memory.used

Loggers
http://localhost:8080/actuator/loggers

Configprops
Information about configuration properties.

http://localhost:8080/actuator/configprops

Change configuration

Offline

With the application down, open the file: /src/main/resources/application.properties and add the line:

logging.level.org.hibernate.SQL=DEBUG

Online
With application up and running, you can change the configuration using a simple cURL command.

curl -X “POST” “http://localhost:8080/actuator/loggers/org.hibernate.SQL" -H “Content-Type: application/json; charset=utf-8” -d $’{ “configuredLevel”: “DEBUG” }’
  • curl: http interaction.
  • -X: POST Methos.
  • -H: add a new header, JSON.
  • -d: payload.

Monitoring

There are many applications you can easily integrate with Spring Boot Actuator to monitor: New Relic, DataDog, Prometheus, Grafana.

Security

All features are enabled by the default except shutdown for security reasons. You can enable/disable features changing the configuration on the file: application.properties.

Enable

management.endpoints.web.exposure.include=beans,metrics,info,health,loggers

Disable

management.endpoints.jmx.exposure.exclude=beans

Conclusion

This is a simple practice application to show how you can manage and monitor you application on production environment using Spring Boot Actuator.

References

Fonte Aplicação GIT
Spring Boot Features

Distro Watch
Spring Initializer

--

--