The microservices enable the rapid, frequent and reliable delivery of large, complex applications. Monitoring, managing or troubleshooting poor performing microservice can be tedious task sometime, especially if you have to go to multiple places to look at what is happening under the hood. Be it looking for behavior of an application through log file, threads, heap memory etc. And you would certainly like all these things at one place for quick monitoring of your spring boot applications.
Although Spring Boot Actuator can do the magic for you if you have single app to look after. When you have multiple applications to monitor, Spring Boot Admin is a great choice!
Spring Boot Admin Server is an application used to manage and monitor your Microservice applications. CodeCentric team had developed Spring Boot Admin UI to manage your Spring Boot application actuator endpoints.
Each microservice acts as a client and has to register to Spring boot admin server. Behind the curtain, admin server leverages application's actuator endpoints to gather all the data.
Lets look at what is needed to build a Spring Boot Admin server.
- Go to https://start.spring.io/ and Generate a starter project with mentioned dependencies.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> </dependency>
- Add the @EnableAdminServer annotation to your main application class. The @EnableAdminServer annotation will turn your spring boot application to Admin Server and monitor all other microservices.
- Define application name and port in application.properties
And that's all about it! Your Spring Boot Admin server is ready to run and serve the clients connecting to it.
Tomcat server will be started on the port 9090 as specified. You can launch Spring Boot Admin UI by browsing http://localhost:9090
Now that our Admin server is all setup, lets write couple of client applications to place on monitoring.
You will need to add below dependencies to pom.xml file.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> </dependency>
I have created two REST API applications for demo. We need to setup these as a client to connect to admin server.
We need to add few properties to application.properties file as given below.
Note: From Spring Boot 2 and above, actuator endpoints except health and info are restricted. That why we are exposing all the endpoints by specifying the properties explicitly.
# Application spring.application.name=Demo API server.port=8080 # Spring boot admin server spring.boot.admin.client.url=http://localhost:9090 # Actuator endpoints properties management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always # To monitor log file on admin server logging.file.name=demo_api.log logging.logback.rollingpolicy.max-history=5 logging.logback.rollingpolicy.max-file-size=10MB
Once client applications are started, they will be registered to admin server.
You can now see the applications being monitored on Spring Boot Admin UI Wallboard with their overall status.
Applications tab will show you the details on number of applications up/down, overall status, lets you filter the apps etc.
Journal tab will give you the audit details on startup/shutdown of a particular application.
Lets look at what other granular details are being provided for each of these applications.
- You can look at overall health of an application instance.
- Add metrics as per your requirement.
- Configuration details and scheduled tasks if any
- You can monitor and download logs of an application
- You can set the logger level as well
- JVM related details on Thread and Heap dump.
- URI mappings of an application
- Cache details of an application
As you can see, we have all the details about an application at one place now.
Lets look at few other modules provided by Spring Boot Admin.
- We had exposed all the actuator endpoints to admin server which in turn will expose all the sensitive information about an application as well. It becomes pivotal to secure admin UI and have only authorized personnel look at it.
You can refer https://codecentric.github.io/spring-boot-admin/current/#securing-spring-boot-admin to secure admin UI.
- Notification about a particular event in an application is also of great importance to avoid eye on the glass monitoring. Spring boot admin notifications module provides lot of options to notify user via Email, MS teams, Slack etc.
Checkout https://codecentric.github.io/spring-boot-admin/current/#_notifications for more details.
I hope you enjoyed reading about Spring Boot Admin in this article. Leave your reactions and comments below if you found this useful. Keep Learning!