Spring Boot Admin: How to use it

Daniel S. Blanco
3 min readMar 6, 2022

--

We have already seen a post about the use of spring boot admin and how to configure it manually or through a Service Discovery like Eureka. In this post, we will see a little more about how to use it. For this, we have used the applications we configured in the previous post, here you can see more information. With the following library versions:

  • Spring Boot: 2.5.7
  • Spring Admin: 2.5.4

To show the version number associated with the application we must configure it through the pom.xml file, the spring-boot-maven-plugin, and the build-info option. This will automatically create the META-INF/build-info.properties file that will transmit the information to the SBA.

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>

We can also add tags to the information of our application that allows us to categorize it, such as the environment where it is deployed. These tags will be transferred through the endpoint info. Configuration example:

#using the info endpoint
info.tags.environment=test

In the Insights side menu, we will have a multitude of information, from metrics, environment information, scheduled tasks, or configuration properties. In the metrics section, we will be able to have at a glance configured different measurements that allow us to check how the application is working.

We can also modify the log trace levels of any of the applications, making it possible to lower or raise them.

And although the official documentation indicates that a minimum configuration is required. Using log4j2 and the indicated versions, it has not been necessary to modify the configuration file so that logs are modifiable and the change takes effect through SBA.

To add interaction with JMX beans, we need to add the org.jolokia.jolokia-core dependency and the spring.jmx.enabled property in the application.properties configuration file. This way we will have read access to the attributes of the beans and in some cases even write access. In addition, we will also be able to make invocations on the methods of these beans.

Finally, let’s show how we can configure notifications, these will be displayed when the applications are stopped. There are multiple ways to make notifications, via Slack, Telegram, Teams, etc.
We will use the traditional method of sending emails. And for this, we will use MockMock a very basic SMTP server that will allow us to receive test emails. This server must be started with administrator permissions to allow the use of ports and through the following command, where the first parameter is the SMTP server port and the second the web browser port that will allow us to see the emails:

sudo java -jar MockMock.jar -p 25 -h 8282

And now we must configure SBA for the use of mails. On the one hand, we add the spring-boot-starter-mail dependency and on the other hand the configuration for sending mails:

spring.mail.host=localhost
spring.mail.port=25
spring.mail.properties.mail.transport.protocol=smtp

spring.boot.admin.notify.mail.to=receiver@example.com
spring.boot.admin.notify.mail.from=sender@example.com

Now when an application crashes we will receive the following mail:

I hope this post will help you to better understand this amazing monitoring tool like Spring Boot Admin.

spring.boot.admin.notify.mail.to=receiver@example.com
spring.boot.admin.notify.mail.from=sender@example.com

--

--