07 使用admin进行服务监控

springcloud中的admin模块用于服务监控,本节将阐述该模块。

1、环境约束

  • win10 64为操作系统
  • idea2018.1.5
  • maven-3.0.5
  • jdk-8u162-windows-x64

2、前提约束

3、操作步骤

3.1 创建admin-server

  • 创建一个springcloud项目,包括springweb,eureka client,admin server,包括以下关键依赖:
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

注意:springboot的版本是2.1.1.RELEASE,springcloud的版本是Greenwich.SR1,admin 的版本是2.1.2

  • 在主启动类上除@SpringBootApplication之外加入以下注解:
@EnableAdminServer
@EnableEurekaClient
  • 修改appliation.yml
server:
  port: 8001
spring:
  application:
    name: admin-server
eureka:
  client:
    service-url:
      defaultZone: http://localhost:7561/eureka/
management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        include: health,info

3.2 创建admin-client

  • 创建一个springcloud项目,包括springweb,eureka client,admin client,包括以下关键依赖:
       <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.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

注意:springboot的版本是2.1.1.RELEASE,springcloud的版本是Greenwich.SR1,admin 的版本是2.1.2

  • 修改application.yml,内容如下:
server:
  port: 8002
spring:
  application:
    name: admin-client
  boot:
    admin:
      client:
        url: http://localhost:8001

eureka:
  client:
    service-url:
      defaultZone: http://localhost:7561/eureka/

3.3 测试

依次启动eureka,admin server,admin client,在浏览器中访问http://localhost:8001/#/wallboard,出现以下监控界面:
wallboard
以上就是使用admin进行的服务监控。

猜你喜欢

转载自www.cnblogs.com/alichengxuyuan/p/12581319.html
07