SpringBoot | 使用 spring-boot-admin 对 Spring Boot 服务进行监控

server端项目依赖

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

配置文件 application.properties

server.port=8181

spring.application.name=spring-boot-admin-server

启动类

package com.xiaobu;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


/**
 * @author xiaobu
 */
@EnableAdminServer
@SpringBootApplication
public class SpringbootAdminServerApplication implements CommandLineRunner {

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

    @Override
    public void run(String... args) throws Exception {
        System.out.println("服务启动成功......");
    }
}

启动服务端,浏览器访问http://localhost:8181,即可看到下面的效果。
1

Admin Client 端

项目依赖:

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

        <!-- Admin client 端-->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.1.0</version>
        </dependency>

配置文件 application.properties

#springbootadmin 监控
spring.application.name=Admin Client
#配置 Admin Server 的地址
spring.boot.admin.client.url=http://localhost:8181
#打开客户端 Actuator 的监控。
management.endpoints.web.exposure.include=*

启动类

package com.xiaobu;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringbootAdminClientApplication {

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

}

启动Client后,服务器会自动检测到客户端的变化,并展示应用

1567567005(1).jpg

点击实例详情查看详细监控信息:

1567567196.jpg

已知bug

java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [MUST_DISPATCH]

发布了152 篇原创文章 · 获赞 18 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/tanhongwei1994/article/details/100535491