DEV Community 👩‍💻👨‍💻

Cover image for Monitoring Microservices with Spring Boot Admin
Devanand Ukalkar
Devanand Ukalkar

Posted on

Monitoring Microservices with Spring Boot Admin

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.

Image description

Lets look at what is needed to build a Spring Boot Admin server.

Maven

        <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>
Enter fullscreen mode Exit fullscreen mode

Image description

  • 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.

Image description

  • Define application name and port in application.properties
spring.application.name=adminserver
server.port=9090
Enter fullscreen mode Exit fullscreen mode

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

Image description

Image description


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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Once client applications are started, they will be registered to admin server.

Image description

You can now see the applications being monitored on Spring Boot Admin UI Wallboard with their overall status.

Image description

Applications tab will show you the details on number of applications up/down, overall status, lets you filter the apps etc.

Image description

Journal tab will give you the audit details on startup/shutdown of a particular application.

Image description

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.

Image description

  • Add metrics as per your requirement.

Image description

  • Details on system environment
    Image description

  • Application beans

Image description

  • Configuration details and scheduled tasks if any

Image description

  • You can monitor and download logs of an application

Image description

  • You can set the logger level as well

Image description

  • JVM related details on Thread and Heap dump.

Image description

  • URI mappings of an application

Image description

  • Cache details of an application

Image description

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!

Top comments (0)

🌚 Life is too short to browse without dark mode