SoFunction
Updated on 2025-04-15

SpringBoot Admin's application monitoring and alarm configuration method

introduction

In the context of wide application of microservice architectures and distributed systems, it is particularly important to effectively monitor the operation status of applications and promptly detect potential problems. Spring Boot Admin is an open source monitoring solution designed for Spring Boot applications. It provides an intuitive Web UI interface, allowing developers and operation staff to monitor application metrics, view logs, manage beans, check environment configuration, etc. in real time. This article will explore the core functions, configuration methods and how to implement effective application monitoring and alarm systems in Spring Boot Admin, helping the team build a more robust and reliable application ecosystem.

1. Spring Boot Admin infrastructure

Spring Boot Admin consists of two parts: the server and the client. The server provides a Web UI interface to collect and display client information; the client pushes application information to the server or allows the server to pull information. This architecture allows Spring Boot Admin to centrally monitor multiple Spring Boot applications.

To get started with Spring Boot Admin, you need to create a server-side application:

<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.7.0</version>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Add on the application entry class@EnableAdminServerannotation:

import ;
import ;
import ;

@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {
    public static void main(String[] args) {
        (, args);
    }
}

Next, configure the client application that needs to be monitored:

<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.7.0</version>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

On the clientConfigure the Admin Server address and Actuator endpoint in the file:

# Admin Server Address=http://localhost:8080
=${}

# Expose Actuator endpoints=*
-details=always

Through the above configuration, the client application will automatically register with Admin Server and start reporting monitoring data.

2. Monitoring indicators and visualization

Spring Boot Admin is based on the endpoints provided by Spring Boot Actuator and demonstrates a wealth of application monitoring metrics, including:

2.1 Health status monitoring

Health status is the most basic monitoring indicator, showing the status of the application and its dependent components (database, cache, message queue, etc.):

import ;
import ;
import ;

@Component
public class CustomHealthIndicator implements HealthIndicator {
    
    @Override
    public Health health() {
        int errorCode = checkService(); // Custom health check logic        if (errorCode != 0) {
            return ()
                    .withDetail("Error Code", errorCode)
                    .build();
        }
        return ().build();
    }
    
    private int checkService() {
        // Implement specific service inspection logic        return 0; // 0 means normal    }
}

2.2 Performance indicator monitoring

Spring Boot Admin shows key performance metrics such as JVM memory usage, thread status, GC activity, etc.:

# Configure Micrometer to collect more detailed performance metrics=true
=true

Custom business metrics can be registered via Micrometer:

import ;
import ;
import ;

@Service
public class OrderService {
    
    private final Counter orderCounter;
    
    public OrderService(MeterRegistry registry) {
         = ("")
                .description("Number of orders created")
                .register(registry);
    }
    
    public void createOrder() {
        // Business logic        ();
    }
}

2.3 Log viewing

Spring Boot Admin allows you to view application logs directly on the web interface, and the configuration method is as follows:

# Configure log file path=logs/
# Enable logfile endpoint=true
-file=${}

3. Alarm configuration

Spring Boot Admin supports multiple alarm modes, triggering notifications when the application state changes (for example, from UP to DOWN):

3.1 Email Alarm

To configure email alerts, you need to add dependencies:

<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

Add mail configuration in the Admin Server configuration file:

# Email Server Configuration=
=25
=admin
=secret
=true
=true

# Alarm configuration=admin@
=spring-boot-admin@
=classpath:/email-templates/
-changes=UNKNOWN:UP,DOWN:UNKNOWN

3.2 DingTalk/Enterprise WeChat Alarm

For enterprise environments, you can configure DingTalk or Enterprise WeChat alerts:

import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;

@Component
public class DingTalkNotifier extends AbstractStatusChangeNotifier {
    
    private final String webhookUrl = "/robot/send?access_token=xxx";
    private final RestTemplate restTemplate = new RestTemplate();
    
    public DingTalkNotifier(InstanceRepository repository) {
        super(repository);
    }
    
    @Override
    protected Mono&lt;Void&gt; doNotify(InstanceEvent event, Instance instance) {
        return (() -&gt; {
            HttpHeaders headers = new HttpHeaders();
            (MediaType.APPLICATION_JSON);
            
            String message = ("""
                    {
                        "msgtype": "text",
                        "text": {
                            "content": "Application status change: %s instance %s state changes from %s to %s"
                        }
                    }
                    """,
                    ().getName(),
                    (),
                    getLastStatus(()),
                    ().getStatus());
            
            HttpEntity&lt;String&gt; request = new HttpEntity&lt;&gt;(message, headers);
            (webhookUrl, request, );
        });
    }
}

3.3 Custom alarm rules

Spring Boot Admin allows for the implementation of complex alarm rules through custom Notifiers:

import ;
import ;
import ;
import ;
import ;

@Component
public class CustomNotifier extends AbstractStatusChangeNotifier {
    
    public CustomNotifier(InstanceRepository repository) {
        super(repository);
    }
    
    @Override
    protected boolean shouldNotify(InstanceEvent event, Instance instance) {
        // Custom alarm trigger conditions        if (().isDown()) {
            // Check whether it is a production environment            String env = ().getMetadata().get("environment");
            return "production".equals(env);
        }
        return false;
    }
    
    @Override
    protected Mono&lt;Void&gt; doNotify(InstanceEvent event, Instance instance) {
        return (() -&gt; {
            // Implement alarm logic, such as calling the external alarm system API        });
    }
}

4. Security configuration

In production environments, security protection should be added for Spring Boot Admin. The most common way is to integrate Spring Security:

<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

Configure basic authentication:

import ;
import ;
import ;
import ;
import ;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        ("redirectTo");
        ("/");
        
        ()
                .antMatchers("/assets/**").permitAll()
                .antMatchers("/login").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login").successHandler(successHandler)
                .and()
                .logout().logoutUrl("/logout")
                .and()
                .httpBasic()
                .and()
                .csrf().csrfTokenRepository(());
    }
}

To register a client with a security-protected Admin Server, you need to provide credentials:

=admin
=admin

5. Practical application and best practices

5.1 Integrated Service Discovery

In a microservice environment, you can integrate service discovery mechanisms such as Eureka and Consul to automatically register applications:

<dependency>
    <groupId></groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
@Configuration
public class DiscoveryConfig {
    
    @Bean
    public EurekaDiscoveryClient discoveryClient(EurekaClient eurekaClient) {
        return new EurekaDiscoveryClient(eurekaClient);
    }
}

5.2 Layered Alarm Policy

Establish a layered alarm strategy and select different notification methods according to the severity of the problem:

  • Minor problem: logging only or sending emails
  • Medium problem: Send enterprise instant messaging notification (DingTalk/Enterprise WeChat)
  • Serious problems: SMS and phone alarms to ensure immediate handling

5.3 Custom dashboard

Create a more powerful monitoring dashboard with Grafana integration with Prometheus:

# Prometheus Configuration=true
=true

Summarize

Spring Boot Admin provides a powerful and concise monitoring solution for Spring Boot applications, demonstrating application health status, performance metrics and configuration information through an intuitive interface. Rationally configure the alarm mechanism to promptly detect and respond to potential problems and improve the reliability and availability of the system. In actual applications, a complete application monitoring system should be built in combination with best practices such as security configuration, service discovery, and layered alarm strategies.

As the complexity of microservices and distributed systems continues to increase, Spring Boot Admin, as a lightweight monitoring tool, can help developers and operation staff better understand application behavior, optimize performance, and quickly locate and solve problems. It is an indispensable monitoring tool for modern Spring Boot applications.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.