Table of Contents
- What is Spring Boot Admin?
- Why Use Spring Boot Admin?
- Setting Up Spring Boot Admin Server
- Registering Clients to the Admin Server
- Exploring Spring Boot Admin Dashboard
- Spring Boot Actuator Health Endpoints
- Custom Health Indicators
- Securing Spring Boot Admin
- Spring Boot Admin Notifications and Alerts
- Summary
1. What is Spring Boot Admin?
Spring Boot Admin is a community-driven project by Codecentric that provides a web-based UI for managing and monitoring Spring Boot applications. It leverages Spring Boot Actuator under the hood to gather metrics and system health data, presenting it in a centralized, visual format. It’s especially useful when you have multiple microservices running and need a single pane of glass to monitor them all.
2. Why Use Spring Boot Admin?
- Monitor multiple Spring Boot applications in one dashboard
- Visual representation of application metrics, logs, environment, and endpoints
- Easily track application status and health
- Customize health checks and alerts
- Centralize management of log levels, threads, and JVM state
3. Setting Up Spring Boot Admin Server
To set up a Spring Boot Admin Server:
Add Dependencies
In your Admin Server’s pom.xml
:
xmlCopyEdit<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>3.1.8</version> <!-- Use compatible version -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
Enable Admin Server
javaCopyEdit@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
Basic Config in application.properties
propertiesCopyEditserver.port=8080
spring.application.name=admin-server
4. Registering Clients to the Admin Server
On each Spring Boot application you want to monitor:
Add Client Dependencies
xmlCopyEdit<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>3.1.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Configure Application Properties
propertiesCopyEditspring.application.name=my-app
management.endpoints.web.exposure.include=*
spring.boot.admin.client.url=http://localhost:8080
Ensure that the actuator endpoints are exposed and accessible.
5. Exploring Spring Boot Admin Dashboard
Once everything is configured:
- Visit
http://localhost:8080
(Admin Server UI) - You’ll see the registered clients with their:
- Health
- Metrics
- Beans
- Environment variables
- JVM memory, threads, GC info
- Loggers and configuration
- Custom endpoints
Each client is continuously monitored and updated in real time.
6. Spring Boot Actuator Health Endpoints
Spring Boot Admin uses the actuator’s /health
endpoint to determine if an application is up or down.
By default, the /actuator/health
shows a simple “UP” or “DOWN”. You can show detailed health information by setting:
propertiesCopyEditmanagement.endpoint.health.show-details=always
Default Health Indicators
Spring Boot includes indicators for:
- Disk space
- Database
- Redis, MongoDB
- Ping
- Custom indicators
7. Custom Health Indicators
You can define your own logic for health reporting:
javaCopyEdit@Component
public class MyCustomHealthIndicator implements HealthIndicator {
@Override
public Health health() {
// Your custom logic
boolean isHealthy = checkService();
if (isHealthy) {
return Health.up().withDetail("customService", "Available").build();
} else {
return Health.down().withDetail("customService", "Unavailable").build();
}
}
private boolean checkService() {
// Simulate a service check
return true;
}
}
This will appear under the /actuator/health
and in the Spring Boot Admin dashboard.
8. Securing Spring Boot Admin
You can secure the Admin UI and client registration using Spring Security:
Security Configuration (Server)
javaCopyEdit@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/assets/**", "/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login").permitAll()
.and()
.logout().permitAll();
}
}
You can also secure the actuator endpoints on each client.
9. Spring Boot Admin Notifications and Alerts
Spring Boot Admin supports notifications via:
- Slack
- PagerDuty
- HipChat
- OpsGenie
- Let’s you define thresholds and alerting rules
To enable Slack integration, add:
xmlCopyEdit<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-notifier-slack</artifactId>
</dependency>
And configure:
propertiesCopyEditspring.boot.admin.notify.slack.enabled=true
spring.boot.admin.notify.slack.webhook-url=https://hooks.slack.com/services/...
10. Summary
Spring Boot Admin combined with Actuator provides a comprehensive, real-time dashboard for managing and monitoring Spring Boot applications. It scales well for microservices, enhances observability, and supports both out-of-the-box and custom metrics and health indicators. It also improves operational response time by enabling secure, centralized monitoring with real-time notifications.