Master Spring Boot Admin: Build a Full‑Featured Monitoring Dashboard
This guide walks you through setting up Spring Boot Admin, covering server and client configuration, essential monitoring features, security setup, custom notification code, and integration with microservices and Nacos for comprehensive application health management.
Overview
Spring Boot Admin provides management and monitoring for Spring Boot applications, allowing you to check health, online status, JVM metrics, and more.
Architecture
It consists of a server ( spring-boot-admin-server) and a client ( spring-boot-admin-client) that communicate via HTTP. In a monolithic project the client must be added to be monitored. In Spring Cloud projects the server can pull application information directly from the registry without each microservice integrating the client.
Key Features
Display application health status
Monitor application up/down events
View JVM and thread information
Visualize and download log files
Dynamically change log levels
Trace HTTP request information
Server Setup
1. Create a Spring Boot project
Add the following dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>Enable the admin server in the main class: @EnableAdminServer Configure Spring Security (example):
import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath;
public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");
http.authorizeRequests()
.antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login", "/css/**", "/js/**", "/image/*").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
.httpBasic().and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers("/instances", "/actuator/**");
}
}Add the following application.yml configuration:
server:
port: 9111
spring:
boot:
admin:
ui:
title: HMB Service Monitoring Center
client:
instance:
metadata:
tags:
environment: local
probed-endpoints: health,env,metrics,httptrace:trace,threaddump:dump,jolokia,info,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents
monitor:
default-timeout: 20000
security:
user:
name: admin
password: admin
management:
trace:
http:
enabled: true
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: alwaysRun the application and access http://localhost:9111 with the credentials admin / admin.
Client Setup
1. Add dependencies
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Configure application.yml for the client:
server:
port: 9222
spring:
application:
name: client
boot:
admin:
client:
url: http://localhost:9111
username: admin
password: admin
instance:
prefer-ip: true
management:
trace:
http:
enabled: true
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
logfile:
external-file: ./logs/client-info.logStart the client; it will register with the server and appear in the dashboard.
Custom Notification Example
The following notifier sends a warning when a service status changes:
import de.codecentric.boot.admin.server.domain.entities.Instance;
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
import de.codecentric.boot.admin.server.domain.events.InstanceEvent;
import de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
@Component
public class WarnNotifier extends AbstractStatusChangeNotifier {
public WarnNotifier(InstanceRepository repository) {
super(repository);
}
@Override
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
String serviceName = instance.getRegistration().getName();
String serviceUrl = instance.getRegistration().getServiceUrl();
String status = instance.getStatusInfo().getStatus();
Map<String, Object> details = instance.getStatusInfo().getDetails();
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
StringBuilder str = new StringBuilder();
str.append("Service: 【" + serviceName + "】
");
str.append("Status: 【" + status + "】
");
str.append("URL: 【" + serviceUrl + "】
");
str.append("Time: " + format + "
");
return Mono.fromRunnable(() -> {
// implement your alerting logic here, e.g., send SMS
});
}
}Microservice Integration
When using Nacos as a service registry, add the Nacos discovery dependency and configure the address in application.yml:
spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848The client can discover services without adding the admin client dependency, as Spring Boot Admin will locate services in the registry. If a service defines a custom context-path, add the corresponding management path in the configuration:
spring:
cloud:
nacos:
discovery:
metadata:
management:
context-path: ${server.servlet.context-path}/actuatorSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Interview Crash Guide
Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
