SpringBootadmin2.0詳解-創(chuàng)新互聯(lián)

一、什么是Spring Boot Admin ?

Spring Boot Admin是一個開源社區(qū)項目,用于管理和監(jiān)控SpringBoot應用程序。 應用程序作為Spring Boot Admin Client向為Spring Boot Admin Server注冊(通過HTTP)或使用SpringCloud注冊中心(例如Eureka,Consul)發(fā)現(xiàn)。 UI是的Vue.js應用程序,展示Spring Boot Admin Client的Actuator端點上的一些監(jiān)控。服務端采用Spring WebFlux + Netty的方式。Spring Boot Admin為注冊的應用程序提供以下功能:

成都創(chuàng)新互聯(lián)公司2013年開創(chuàng)至今,先為龍泉等服務建站,龍泉等地企業(yè),進行企業(yè)商務咨詢服務。為龍泉企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。
  • 顯示健康狀況
  • 顯示詳細信息,例如
    • JVM和內(nèi)存指標
    • micrometer.io指標
    • 數(shù)據(jù)源指標
    • 緩存指標
  • 顯示構(gòu)建信息編號
  • 關(guān)注并下載日志文件
  • 查看jvm system-和environment-properties
  • 查看Spring Boot配置屬性
  • 支持Spring Cloud的postable / env-和/ refresh-endpoint
  • 輕松的日志級管理
  • 與JMX-beans交互
  • 查看線程轉(zhuǎn)儲
  • 查看http-traces
  • 查看auditevents
  • 查看http-endpoints
  • 查看計劃任務
  • 查看和刪除活動會話(使用spring-session)
  • 查看Flyway / Liquibase數(shù)據(jù)庫遷移
  • 下載heapdump
  • 狀態(tài)變更通知(通過電子郵件,Slack,Hipchat,......)
  • 狀態(tài)更改的事件日志(非持久性)

二、入門

1. 創(chuàng)建 Spring Boot Admin Server

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.gf</groupId>
    <artifactId>admin-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>admin-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.1.0</spring-boot-admin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
application.yml
spring:
  application:
    name: admin-server
server:
  port: 8769
啟動類 AdminServerApplication

啟動類加上@EnableAdminServer注解,開啟AdminServer的功能:

@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {

    public static void main(String[] args) {
        SpringApplication.run( AdminServerApplication.class, args );
    }

}

2. 創(chuàng)建 Spring Boot Admin Client

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.gf</groupId>
    <artifactId>admin-client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>admin-client</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.1.0</spring-boot-admin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
application.yml
  • spring.boot.admin.client.url:要注冊的Spring Boot Admin Server的URL。
  • management.endpoints.web.exposure.include:與Spring Boot 2一樣,默認情況下,大多數(shù)actuator的端口都不會通過http公開,* 代表公開所有這些端點。對于生產(chǎn)環(huán)境,應該仔細選擇要公開的端點。
spring:
  application:
    name: admin-client
  boot:
    admin:
      client:
        url: http://localhost:8769
server:
  port: 8768

management:
  endpoints:
   web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: ALWAYS
啟動類 AdminClientApplication
@SpringBootApplication
public class AdminClientApplication {

    public static void main(String[] args) {
        SpringApplication.run( AdminClientApplication.class, args );
    }

}

啟動兩個工程,在瀏覽器上輸入localhost:8769 ,瀏覽器顯示的界面如下:

查看wallboard:

Spring Boot admin 2.0 詳解

點擊wallboard,可以查看admin-client具體的信息,比如內(nèi)存狀態(tài)信息:

Spring Boot admin 2.0 詳解

查看spring bean的情況:

Spring Boot admin 2.0 詳解

查看應用程序運行狀況,信息和詳細:

Spring Boot admin 2.0 詳解

還有很多監(jiān)控信息,多點一點就知道。

三、集成 Eureka

1. 創(chuàng)建 sc-eureka-server

這是一個 eureka-server 注冊中心。

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.gf</groupId>
    <artifactId>sc-admin-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sc-admin-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.1.0</spring-boot-admin.version>
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
application.yml
spring:
  application:
    name: sc-eureka-server
server:
  port: 8761
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka
    register-with-eureka: false
    fetch-registry: false
management:
  endpoints:
   web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
啟動類 ScEurekaServerApplication
@SpringBootApplication
@EnableEurekaServer
public class ScEurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run( ScEurekaServerApplication.class, args );
    }

}

2. 創(chuàng)建 sc-admin-server

這是一個 Spring Boot Admin Server端。

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.gf</groupId>
    <artifactId>sc-admin-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sc-admin-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.1.0</spring-boot-admin.version>
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
application.yml
spring:
  application:
    name: admin-server
server:
  port: 8769
eureka:
  client:
    registryFetchIntervalSeconds: 5
    service-url:
      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health

management:
  endpoints:
   web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
啟動類 ScAdminServerApplication
@SpringBootApplication
@EnableAdminServer
@EnableDiscoveryClient
public class ScAdminServerApplication {

    public static void main(String[] args) {
        SpringApplication.run( ScAdminServerApplication.class, args );
    }

}

3. 創(chuàng)建 sc-admin-client

這是一個 Spring Boot Admin client 端。

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.gf</groupId>
    <artifactId>sc-admin-client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sc-admin-client</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.1.0</spring-boot-admin.version>
        <spring-cloud.version>Finchley.SR2</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
application.yml
spring:
  application:
    name: sc-admin-client
eureka:
  instance:
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health

  client:
    registryFetchIntervalSeconds: 5
    service-url:
      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management:
  endpoints:
   web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
server:
  port: 8762
啟動類 ScAdminClientApplication
@SpringBootApplication
@EnableDiscoveryClient
public class ScAdminClientApplication {

    public static void main(String[] args) {
        SpringApplication.run( ScAdminClientApplication.class, args );
    }

}

啟動三個工程,訪問localhost:8769,出現(xiàn)如下界面:

Spring Boot admin 2.0 詳解

admin 會自己拉取 Eureka 上注冊的 app 信息,主動去注冊。這也是唯一區(qū)別之前入門中手動注冊的地方,就是 client 端不需要 admin-client 的依賴,也不需要配置 admin 地址了,一切全部由 admin-server 自己實現(xiàn)。這樣的設計對環(huán)境變化很友好,不用改了admin-server后去改所有app 的配置了。

四、集成 Spring Security

Web應用程序中的身份驗證和授權(quán)有多種方法,因此Spring Boot Admin不提供默認方法。默認情況下,spring-boot-admin-server-ui提供登錄頁面和注銷按鈕。我們結(jié)合 Spring Security 實現(xiàn)需要用戶名和密碼登錄的安全認證。

sc-admin-server工程的pom文件需要增加以下的依賴:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

在 sc-admin-server工的配置文件 application.yml 中配置 spring security 的用戶名和密碼,這時需要在服務注冊時帶上 metadata-map 的信息,如下:

spring:
  security:
    user:
      name: "admin"
      password: "admin"

eureka:
  instance:
    metadata-map:
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}

@EnableWebSecurity注解以及WebSecurityConfigurerAdapter一起配合提供基于web的security。繼承了WebSecurityConfigurerAdapter之后,再加上幾行代碼,我們就能實現(xiàn)要求用戶在進入應用的任何URL之前都進行驗證的功能,寫一個配置類SecuritySecureConfig繼承WebSecurityConfigurerAdapter,配置如下:

@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 {
        // @formatter:off
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        http.authorizeRequests()
                //授予對所有靜態(tài)資產(chǎn)和登錄頁面的公共訪問權(quán)限。
                .antMatchers(adminContextPath + "/assets/**").permitAll()
                .antMatchers(adminContextPath + "/login").permitAll()
                //必須對每個其他請求進行身份驗證
                .anyRequest().authenticated()
                .and()
                //配置登錄和注銷
                .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
                .logout().logoutUrl(adminContextPath + "/logout").and()
                //啟用HTTP-Basic支持。這是Spring Boot Admin Client注冊所必需的
                .httpBasic().and();
        // @formatter:on
    }
}

重新訪問 http://localhost:8769/ 會出現(xiàn)登錄界面,密碼是 配置文件中配置好的,賬號 admin 密碼 admin,界面如下:

Spring Boot admin 2.0 詳解

五、通知

1. 郵件通知

在 Spring Boot Admin 中 當注冊的應用程序狀態(tài)更改為DOWN、UNKNOWN、OFFLINE 都可以指定觸發(fā)通知,下面講解配置郵件通知。

在sc-admin-server工程pom文件,加上mail的依賴,如下:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

在配置文件application.yml文件中,配置收發(fā)郵件的配置:

spring:
  mail:
    host: smtp.163.com
    username: xxxx@163.com
    password: xxxx
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: true
            required: true
  boot:
    admin:
      notify:
        mail:
          from: xxxx@163.com
          to: xxxx@qq.com

配置后,重啟sc-admin-server工程,之后若出現(xiàn)注冊的客戶端的狀態(tài)從 UP 變?yōu)?OFFLINE 或其他狀態(tài),服務端就會自動將電子郵件發(fā)送到上面配置的收件地址。

注意 : 配置了郵件通知后,會出現(xiàn) 反復通知 service offline / up。這個問題的原因在于 查詢應用程序的狀態(tài)和信息超時,下面給出兩種解決方案:

#方法一:增加超時時間(單位:ms)

spring.boot.admin.monitor.read-timeout=20000

#方法二:關(guān)閉閉未使用或不重要的檢查點

management.health.db.enabled=false
management.health.mail.enabled=false
management.health.redis.enabled=false
management.health.mongo.enabled=false

2. 自定義通知

可以通過添加實現(xiàn)Notifier接口的Spring Beans來添加您自己的通知程序,最好通過擴展 AbstractEventNotifier或AbstractStatusChangeNotifier。在sc-admin-server工程中編寫一個自定義的通知器:

@Component
public class CustomNotifier  extends AbstractStatusChangeNotifier {
    private static final Logger LOGGER = LoggerFactory.getLogger( LoggingNotifier.class);

    public CustomNotifier(InstanceRepository repository) {
        super(repository);
    }

    @Override
    protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
        return Mono.fromRunnable(() -> {
            if (event instanceof InstanceStatusChangedEvent) {
                LOGGER.info("Instance {} ({}) is {}", instance.getRegistration().getName(), event.getInstance(),
                        ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus());

                String status = ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus();

                switch (status) {
                    // 健康檢查沒通過
                    case "DOWN":
                        System.out.println("發(fā)送 健康檢查沒通過 的通知!");
                        break;
                    // 服務離線
                    case "OFFLINE":
                        System.out.println("發(fā)送 服務離線 的通知!");
                        break;
                    //服務上線
                    case "UP":
                        System.out.println("發(fā)送 服務上線 的通知!");
                        break;
                    // 服務未知異常
                    case "UNKNOWN":
                        System.out.println("發(fā)送 服務未知異常 的通知!");
                        break;
                    default:
                        break;
                }

            } else {
                LOGGER.info("Instance {} ({}) {}", instance.getRegistration().getName(), event.getInstance(),
                        event.getType());
            }
        });
    }
}

源碼:https://github.com/gf-huanchupk/SpringBootLearning/tree/master/springboot-admin

歡迎關(guān)注我的公眾號《程序員果果》,關(guān)注有驚喜~~
Spring Boot admin 2.0 詳解

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

本文名稱:SpringBootadmin2.0詳解-創(chuàng)新互聯(lián)
地址分享:http://bm7419.com/article42/cdgshc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供面包屑導航、網(wǎng)站營銷、標簽優(yōu)化、關(guān)鍵詞優(yōu)化、自適應網(wǎng)站、虛擬主機

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務器托管