This time we will discuss how we can monitor, audit and gather metrics on a spring boot application.
When dealing with a multi-component application such as in a microservice architecture it is very important to manage, audit, gather metrics, health check-up and monitor the different micro-service applications or in our example Spring boot applications. With Spring boot framework there is a library that is easily accessible and configured to provide such production-ready features which are the Spring Boot Actuator. These features are accessible via JMX or HTTP endpoints.
In addition, there is also a community project which is known as Spring Admin that provides an administration that provides a centralized place to access the details submitted by all the registered clients.
In this blog, we will set up the Spring Admin server and a sample client.
Setup the Spring Admin Server
- Using the Sprint STS development environment, create a Spring starter project. Add the following dependencies:
- After the project is created, add the spring-boot-maven-plugin in your pom.xml with goal=build-info.
- Configure application.properties. See file below for description.
- Annotate your Spring boot class with @EnableAdminServer.
- Create a security configuration class. See class below.
Setup the Client
If you will notice the server project contains an admin starter client dependency as well as configuration to connect to itself. It means that we are setting up the server as a client itself.
Here are the steps to set up a client.
- Add spring-boot-admin-starter-client dependency.
- Add the credentials to connect to the admin server in the application.json file. See file below.