Guide to Setting Up Spring Boot Admin for Monitoring Spring Boot Applications
This article provides a step‑by‑step tutorial on installing and configuring Spring Boot Admin, including Maven dependencies, server and client setup, YML properties, security, Nacos registration, email notifications, custom health indicators, and Micrometer metrics to monitor Spring Boot services.
Spring Boot Admin is a powerful monitoring and management tool that visualizes Actuator data, tracks application health, and provides real‑time alerts for Spring Boot services.
Key Features
Display application monitoring status
Application instance up/down monitoring
JVM and thread information
Log visualization and download
Dynamic log level switching
HTTP request tracing
Additional extensible features
Project repository: https://github.com/codecentric/spring-boot-admin
Server Setup (admin‑server)
Add the admin server starter dependency in pom.xml :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.6.RELEASE</version>
</parent>
<properties>
<admin.starter.server.version>2.3.1</admin.starter.server.version>
</properties>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${admin.starter.server.version}</version>
</dependency>Enable the admin server with @EnableAdminServer on the main class:
@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}Typical application.yml configuration:
server:
port: 8000
spring:
application:
name: admin-server
management:
endpoint:
health:
show-details: alwaysClient Service (admin‑order)
Add the client starter dependency:
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring.boot.admin.client.version}</version>
</dependency>Configure the client to register with the server:
spring:
application:
name: admin-order
boot:
admin:
client:
api-path: /admin
url: http://127.0.0.1:8000
instance:
prefer-ip: true
username: admin
password: adminStart the client application with a standard @SpringBootApplication class.
Security Integration
Include spring-boot-starter-security and configure a custom WebSecurityConfigurerAdapter to protect the admin UI.
Nacos Service Discovery
When using Alibaba Nacos, add the discovery starter and set the group to ADMIN so that both server and client can register and discover each other.
Email Notification
Add spring-boot-starter-mail and configure SMTP settings (e.g., QQ mail) in application.yml for admin alerts.
Custom Endpoints
Implement a custom HealthIndicator and InfoContributor to expose additional health and metadata:
@Component
public class MyHealthIndicator implements HealthIndicator {
@Override
public Health health() {
int errorCode = check();
if (errorCode != 0) {
return Health.down()
.withDetail("msg", "error service")
.withDetail("code", 500)
.build();
}
return Health.up().build();
}
private int check() { return 0; }
} @Component
public class AppInfo implements InfoContributor {
@Override
public void contribute(Info.Builder builder) {
builder.withDetail("version", "1.0.RELEASE")
.withDetail("project", "admin-order");
}
}Micrometer Metrics
Spring Boot Actuator integrates Micrometer, allowing you to create custom counters, timers, gauges, and distribution summaries. Example usage in a controller:
@RestController
public class HelloController {
@GetMapping("/sayHi")
public String sayHi(String productNo) {
Metrics.counter("order.counter", "productNo", productNo).increment();
Timer timer = Metrics.timer("order.timer");
timer.record(() -> System.out.println("success"));
Metrics.gauge("order.gauge", 1);
DistributionSummary summary = Metrics.summary("redis.hitRate");
summary.record(1.5);
return "success";
}
}These metrics can be accessed via the Actuator endpoint, e.g., http://127.0.0.1:8100/actuator/metrics/order.counter .
The article concludes with references and promotional links.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
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.