SoFunction
Updated on 2025-05-22

SpringCloud Admin practical health check and in-depth interpretation of full-link alarm

1. Introduction

In the microservice architecture, service health monitoring and fault alarm are the keys to ensuring the stable operation of the system.

Spring Cloud Admin, as the core monitoring tool in the Spring Cloud ecosystem, provides out-of-the-box health checks and alarm functions to help developers monitor and manage services more conveniently.

Real-time alarm - integrates mail, Slack and other alarm channels to build an efficient alarm system.

Centralized management - In-depth analysis of the core advantages and application scenarios of Spring Cloud Admin.

2. Spring Cloud Link Monitoring (Admin) core components

2.1 Spring Boot Actuator: Health Check and Performance Monitoring

Spring Boot Actuator is the core dependency of Spring Cloud Admin, providing rich monitoring endpoints to help developers monitor the health status and performance metrics of the service in real time.

1. Principle

  • Health Check:

Through the /actuator/health endpoint, Actuator can monitor the health status of the service in real time, including database connections, disk space, external service dependencies, etc.

  • Performance monitoring:

Through the /actuator/metrics endpoint, Actuator provides performance metrics such as CPU, memory, threads, and HTTP requests.

  • Custom health checks:

Developers can customize health check logic by implementing the HealthIndicator interface.

2. Example

Default health check

Visit /actuator/health, return to the example:

{
  "status": "UP",
  "components": {
    "db": { "status": "UP" },
    "diskSpace": { "status": "UP" }
  }
}

Custom health checks

Implement the HealthIndicator interface and check the database connection status:

@Component
public class DatabaseHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        if (checkDatabaseConnection()) {
            return ().build();
        } else {
            return ().withDetail("Error", "Database connection failed").build();
        }
    }
}

Visit /actuator/health, return to the example:

{
  "status": "DOWN",
  "components": {
    "db": { "status": "DOWN", "details": { "Error": "Database connection failed" } },
    "diskSpace": { "status": "UP" }
  }
}

2.2 Admin Server: Centralized Monitoring and Management

Admin Server is a core component of Spring Cloud Admin, responsible for centralizing the management of monitoring data for all registered services.

1. Principle

  • Service Discovery: Admin Server automatically discovers services registered with Eureka or Consul and demonstrates their health status and performance metrics.
  • Unified monitoring panel: provides a visual interface to view the operating status of all services in real time.
  • Log management: supports dynamic adjustment of log levels to facilitate problem investigation.

2. Example

Example 1: Register directly to Admin Server.

Project structure

spring-cloud-admin-example1/
├── admin-server/                # Management Service Module│   ├── src/main/java/com/example/
│   ├── src/main/resources/
│   ├── 
├── user-service/                # User Service Module│   ├── src/main/java/com/example/
│   ├── src/main/resources/
│   ├── 
├── order-service/               # Order Service Module│   ├── src/main/java/com/example/
│   ├── src/main/resources/
│   ├── 

Step 1: Start Admin Server

In , add the @EnableAdminServer annotation.

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

Configure Admin Server()

server:
  port: 8080  # Admin Server port

Start Admin Server

Run AdminServerApplication, visit http://localhost:8080, and view the Admin Server Control Panel.

Step 2: Register the client service to Admin Server

user-service and order-service are two separate Spring Boot projects.

Add Spring Cloud Admin client dependencies ()

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

Configure the client in

spring:
  boot:
    admin:
      client:
        url: http://localhost:8080  # Admin Server Addressserver:
  port: 8081  # user-service port

Start the client service

Run UserServiceApplication and OrderServiceApplication respectively.

Visit http://localhost:8080 to see if user-service and order-service are successfully registered.

Example 2: Use Eureka as a Service Registration and Discovery Center

Project structure

spring-cloud-admin-example2/
├── eureka-server/               # Eureka Service Registration Center Module│   ├── src/main/java/com/example/
│   ├── src/main/resources/
│   ├── 
├── admin-server/                # Management Service Module│   ├── src/main/java/com/example/
│   ├── src/main/resources/
│   ├── 
├── user-service/                # User Service Module│   ├── src/main/java/com/example/
│   ├── src/main/resources/
│   ├── 
├── order-service/               # Order Service Module│   ├── src/main/java/com/example/
│   ├── src/main/resources/
│   ├── 

Step 1: Start Eureka Server

Add the @EnableEurekaServer annotation in .

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

Configure Eureka Server in

server:
  port: 8761  # Eureka Server Porteureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false  # Eureka Server does not register itself    fetch-registry: false

Start Eureka Server

Run EurekaServerApplication, visit http://localhost:8761, and view the Eureka Control Panel.

Step 2: Start Admin Server

Add the @EnableAdminServer annotation in .

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

Configure Admin Server in to discover services from Eureka

spring:
  application:
    name: admin-server  # Admin Server Name  cloud:
    discovery:
      enabled: true  # Enable service discoveryeureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka  # Eureka Server address

Start Admin Server

Run AdminServerApplication, visit http://localhost:8080, and view the Admin Server Control Panel.

Step 3: Register the client service to Eureka

user-service and order-service are two separate Spring Boot projects.

Add Spring Cloud Admin client and Eureka client dependencies in

<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Configure the client in

spring:
  application:
    name: user-service  # Service Name  cloud:
    discovery:
      enabled: true  # Enable service discovery  boot:
    admin:
      client:
        enabled: true  # Enable Admin Clienteureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka  # Eureka Server Addressserver:
  port: 8081  # user-service port

Start the client service

  • Run UserServiceApplication and OrderServiceApplication respectively.
  • Visit http://localhost:8761 to check whether the service is registered with Eureka.
  • Visit http://localhost:8080 to see if the service is registered with Admin Server.

3. Summary

  • Register directly to Admin Server: Suitable for small projects or test environments.
  • Register with Eureka: Suitable for production environments and supports large-scale microservice architectures.

2.3 Alarm notification module: real-time alarm and notification

Spring Cloud Admin supports multiple alarm channels to help developers receive notifications in a timely manner when service abnormalities are not available.

1. Principle

  • Mail Alarm: Through SMTP configuration, the alarm message is sent to the specified mailbox.
  • Slack Alarm: Through Webhook integration Slack, push alarm information to the specified channel.
  • Multi-channel alarm: supports configuring multiple alarm channels at the same time to realize hierarchical alarms.

2. Example

Example 1: Mail Alarm Configuration

In the Admin Server file

spring:
  mail:
    host:   # SMTP Server Address    port: 587               # SMTP port    username: user@  # Send email    password: yourpassword  # Send email password  cloud:
    admin:
      notify:
        mail:
          enabled: true    # Enable email alerts          to: admin@  # Incoming email

Verify email alert

  • 1. Start admin-server.
  • 2. Simulate service failure (such as shutting down user-service).
  • 3. Check the receiving email address and observe whether you have received an alarm email.

Example 2: Slack Alarm Configuration

In the Admin Server file

spring:
  cloud:
    admin:
      notify:
        slack:
          enabled: true  # Enable Slack Alarm          webhook-url: /services/your/webhook  # Slack Webhook URL

Verify Slack Alarm

  • 1. Start admin-server.
  • 2. Simulate service failure (such as closing order-service).
  • 3. Check the Slack channel to see if you have received an alarm message.

Example 3: Multi-channel Alarm Configuration

Configure both email and Slack alarms, and you can add both email and Slack configurations in:

spring:
  mail:
    host: 
    port: 587
    username: user@
    password: yourpassword
  cloud:
    admin:
      notify:
        mail:
          enabled: true
          to: admin@
        slack:
          enabled: true
          webhook-url: /services/your/webhook

Verify alarm

Simulate service failure

  • Close user-service or order-service.
  • Observe the health status changes of the services in the Admin Server control panel.

Check alarm notification

  • Email Alarm: Check the receiving email address to confirm whether the alarm email has been received.
  • Slack Alarm: Check the Slack channel to confirm whether the alarm message has been received.

3. Summary

  • Mail Alarm: Configure SMTP information in , and enable mail alarm.
  • Slack Alarm: Configure the Slack Webhook URL in , and enable Slack Alarm.
  • Multi-channel alarm: Email and Slack alarms can be configured at the same time to realize hierarchical notifications.

Through the above configuration example, readers can easily implement the alarm notification function of Spring Cloud Admin to ensure that notifications are received in a timely manner when service abnormalities are not available.

2.4 Log and tracking integration: troubleshooting and link tracking

Spring Cloud Admin supports log management and link tracking to help developers quickly locate problems.

1. Principle

Log Management

Spring Cloud Admin itself does not directly manage logs, but can dynamically adjust the log level of microservices without restarting the service by integrating the /actuator/loggers endpoint provided by Spring Boot Actuator.

Link Tracking

In Spring Cloud microservice architecture, link tracing is a common requirement and is usually implemented through the following components:

Main components

Spring Cloud Sleuth:

  • Automatically add a unique tracking ID (Trace ID, Span ID) to each request.
  • Record the call links between microservices for easy troubleshooting.

Zipkin:

  • A distributed tracking system for collecting and visualizing link data generated by Sleuth.

Spring Cloud Admin :

It is not directly involved in the generation or storage of link tracking data, but it can provide the following capabilities:

  • Centralized portal: supports quick jump to Zipkin console without accessing microservice tracking pages one by one.
  • Problem positioning: Combining health status and log information, assisting in fault analysis and improving troubleshooting efficiency.

2. Example

Example 1: Dynamically adjust log levels

Dynamically adjust the log level of the service through Admin Server, and it can take effect without restarting the service.

Step 1: Log configuration

# user-service/
spring:
  application:
    name: user-service
  server:
    port: 8081  # Service Port
# Initial log level configurationlogging:
  level:
    : INFO  # Set the log level of the package to INFO
# Enable log management endpointmanagement:
  endpoint:
    loggers:
      enabled: true  # Enable log management endpoints

Step 2: Dynamically adjust log level

Dynamically adjust the log level of the user-service through Admin Server.

Get the service instance ID:

  • 1. Access the Admin Server Control Panel (http://localhost:8080).
  • 2. Find the instance ID of user-service (for example: user-service-8081).

Use the curl command to dynamically adjust the log level:

Adjust the log level of the package from INFO to DEBUG:

curl -X POST http://localhost:8080/instances/user-service-8081/actuator/loggers/ \
     -H "Content-Type: application/json" \
     -d '{"configuredLevel": "DEBUG"}'

Parameter description

  • {instanceId}: The instance ID of the service, which can be viewed in the Admin Server control panel.
  • : The package name that needs to be adjusted at the log level.

Step 3: Verify log level adjustment

Check the log output of user-service and confirm that the log level has been adjusted to DEBUG.

For example, there is the following log code in user-service:

import org.;
import org.;

@RestController
public class UserController {
    private static final Logger logger = ();

    @GetMapping("/users")
    public String getUsers() {
        ("Debug log message");  // Debug log        ("Info log message");   // Information log        return "User list";
    }
}

After adjusting the log level, the Debug log message will be output to the log.

Example 2: Link Tracking Integration

Target

Full-link tracking is achieved through Sleuth + Zipkin, and combined with Spring Cloud Admin fast positioning issues.

Step 1: Add Sleuth and Zipkin dependencies

In the user-service and order-service files, add the following dependencies:

&lt;!-- Sleuth rely --&gt;
&lt;dependency&gt;gt;  
    &lt;groupId&gt;&lt;/groupId&gt;  
    &lt;artifactId&gt;spring-cloud-starter-sleuth&lt;/artifactId&gt;  
&lt;/dependency&gt;  

&lt;!-- Zipkin 客户端rely --&gt;
&lt;dependency&gt;  
    &lt;groupId&gt;&lt;/groupId&gt;  
    &lt;artifactId&gt;spring-cloud-sleuth-zipkin&lt;/artifactId&gt;  
&lt;/dependency&gt;  

Step 2: Configure Zipkin service address

In user-service and order-service, specify the Zipkin server address:

spring:  
  zipkin:  
    base-url: http://localhost:9411  # Zipkin Server Address  sleuth:  
    sampler:  
      probability: 1.0  # Sampling rate(1.0 express 100% collection)  

Step 3: Start Zipkin Server

Quickly start Zipkin with Docker:

docker run -d -p 9411:9411 openzipkin/zipkin  

Step 4: Verify link tracking

Make a request

In the order-service, call the user-service interface (such as /users).

View link data

  • Visit Zipkin console: http://localhost:9411
  • Search for Trace ID to view the complete call link.

Example:

  • order-service ➝ user-service
  • Trace ID: abc123xyz456

Step 5: Integrate Spring Cloud Admin Positioning Issues

Status Monitoring

  • In the Admin Server control panel, a user-service status exception (such as DOWN) is found.

Log Assistance

  • Dynamically adjust the log level of user-service to DEBUG through Admin Server to view detailed error logs.

Jump Zipkin

  • On the service details page of Admin Server, jump directly to the Zipkin console to analyze the complete link of exception requests.

3. Key questions answers

Q1: Is link tracing a feature of Spring Cloud Admin?

no. Link tracing is implemented by Sleuth + Zipkin and is a common capability of Spring Cloud microservices.

What is Admin Server:

  • Provide centralized portals to correlate service health status, logs and link tracking data.
  • Assist developers to quickly locate problems (such as: when service abnormality is not available, jump directly to the Zipkin analysis link).

Q2: Does Admin Server require additional configuration to support link tracing?

no. Admin Server does not require special configuration, just make sure that the microservices are properly integrated with Sleuth + Zipkin.

Admin Server acts as a monitoring portal only and does not store or process link data.

3. Spring Cloud Link Monitoring (Admin) integration example

1. Scene

Build a microservice system containing user-service and order-service, and achieve the following goals through Spring Cloud Admin:

  • Health status and performance indicators of centralized monitoring services.
  • Integrated email alerts to receive service abnormal notifications in real time.

2. Configuration steps and verification

This example is based on Example 1 in Part 2 (Register directly to Admin Server), adding only key integration steps:

Step 1: Admin Server Configuration

  • Create an Admin Server application (see Section 2.2 Example 1 code).
  • After startup, visit http://localhost:8080 to enter the control panel.

Step 2: Client Service Registration

  • Add Admin Client dependencies in user-service and order-service (see Example 1 in Section 2.2).
  • Configuration Points to Admin Server (Code and Configuration Reference Section 2.2).

Step 3: Mail Alarm Integration

  • Configure SMTP and mail receiving addresses in Admin Server (Configuration Code Direct Reuse Example 1).

Step 4: Full-link verification

  • Health Check: Visit the Admin control panel to confirm that the service status is UP.
  • Alarm trigger: manually close user-service, observe the status of the control panel changes to DOWN, and check whether the inbox has received an alarm email.

This example shows how to quickly build a complete link monitoring system including health monitoring, centralized management and real-time alarms, suitable for the rapid implementation of small and medium-sized projects.

4. Best practices for Spring Cloud Link Monitoring (Admin)

4.1 Leveled Alarm Policy

1. Low priority alarm (non-emergency)

  • Notification method: Notify via Slack (Configuration Reference Section 2.3 Example 2).
  • Applicable scenarios: applicable to service downgrades, non-core service abnormalities, temporary performance fluctuations, etc.

2. High priority alarm (critical fault)

  • Notification method: Through dual channels of email + SMS, ensure timely response to core service issues.

Configuration example:

Admin Server

spring:  
  cloud:  
    admin:  
      notify:  
        mail:  
          enabled: true  # Email Configuration Reference Section 2.3 Example 1        sms:  
          enabled: true  
          phone-numbers: +1234567890  # Mobile phone number for receiving text messages 

AWS SNS SMS Service Configuration

aws:  
  sns:  
    topic-arn: arn:aws:sns:us-east-1:1234567890:alert-topic  # SNS Topic ARN    region: us-east-1  # AWS Region    access-key: ${AWS_ACCESS_KEY}  # Inject access key from environment variables    secret-key: ${AWS_SECRET_KEY}  # Inject key from environment variable  

Dependencies

Adding AWS SNS dependencies in Admin Server

<dependency>  
  <groupId></groupId>  
  <artifactId>aws-java-sdk-sns</artifactId>  
  <version>1.12.500</version>  
</dependency>  

Verification steps:

Simulation service downtime

  • Close core services (such as user-service).
  • Observe the Admin Server control panel and confirm that the service status changes to DOWN.

Check alarm notification

  • Email: Log in to admin@ email, confirm receipt of the title [Emergency Alert]
  • Service exception: user-service email.
  • SMS: Check whether the phone +1234567890 has received a SMS containing [CRITICAL] user-service that has been down.

3. Things to note

Sensitive information protection:

  • Access-key and secret-key should be managed through environment variables or configuration centers, and hard-coded is prohibited.

Failed fallback:

  • It is recommended to configure a retry mechanism to avoid the loss of alarms when the SMS service is unavailable.

4.2 Extended monitoring capabilities

1. Customize health checks

  • Extend health check logic by implementing the HealthIndicator interface (Implementation Logic Reference Section 2.1 example), for example:
  • Monitors the state of dependencies of third-party APIs.
  • Detect database connections and cache availability.

2. Dynamic log adjustment

  • Admin Server supports real-time adjustment of service log levels without restarting the service.
  • Operation command reference Section 2.4 Example 1.

4.3 High availability deployment solution

Server clustering

Deploy multiple Admin Server instances to share monitoring data through Redis to improve system availability.

Configuration example (Admin Server Connection Redis)

spring:  
  redis:  
    host: redis-host  
    port: 6379  
  boot:  
    admin:  
      redis:  
        enabled: true  

2. Client retry mechanism

Configure the client to automatically try when Admin Server is temporarily unavailable to improve stability.

Configuration example (client retry)

spring:  
  boot:  
    admin:  
      client:  
        url: http://admin-server:8080  
        retry:  
          max-attempts: 3  
      initial-interval: 1000  

Verification steps

Check the client log and confirm the retry behavior, for example:

Retrying to connect to Admin Server...

4.4 Production environment suggestions

1. Resource Isolation

  • Admin Server is deployed in an independent cluster to avoid competing with business services for resources.

2. Safety reinforcement

  • Add authentication to Actuator endpoints (Integrate Spring Security).
  • Limit the public network exposure of /actuator endpoints to avoid security risks.

3. Monitor data archives

  • Regularly export health check records to Elasticsearch for easy historical traceability and analysis.

Summarize

Core summary

The core values ​​and features of Spring Cloud Admin:

1. Out-of-the-box monitoring solution

  • Based on Spring Boot Actuator, it provides core functions such as health checks (such as database, disk space), performance indicators (CPU, memory) and other core functions.
  • Supports custom health check logic (via the HealthIndicator interface).

2. Multi-channel real-time alarm

  • Integrate notification channels such as email, Slack, etc., and support hierarchical alarm policies (such as Slack push for non-emergency issues, and email triggered by critical faults + SMS).

3. Advantages of centralized management and control

  • The unified monitoring panel displays all service status, supports dynamic adjustment of log levels, and integrates Sleuth/Zipkin to implement link tracking.

4. High availability and scalability

  • Support Admin Server cluster deployment, and combines the client retry mechanism to ensure monitoring stability.

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