springCloud--admin监控使用

Admin监控应用

Spring Boot提供的监控接口,例如:/health、/info等等,实际上除了之前提到的信息,还有其他信息业需要监控:当前处于活跃状态的会话数量、当前应用的并发数、延迟以及其他度量信息。下面我们来了解如何使用spring-boot-admin来监控我们的系统。

admin-server-ui

pom.xml配置:

  1.  
    <parent>
  2.  
    <groupId>org.springframework.boot</groupId>
  3.  
    <artifactId>spring-boot-starter-parent</artifactId>
  4.  
    <version>1.4.3.RELEASE</version>
  5.  
    <relativePath/>
  6.  
    </parent>
  7.  
    <dependencyManagement>
  8.  
    <dependencies>
  9.  
    <dependency>
  10.  
    <groupId>org.springframework.cloud</groupId>
  11.  
    <artifactId>spring-cloud-dependencies</artifactId>
  12.  
    <version>Camden.SR5</version>
  13.  
    <type>pom</type>
  14.  
    <scope>import</scope>
  15.  
    </dependency>
  16.  
    </dependencies>
  17.  
    </dependencyManagement>
  18.  
    <dependencies>
  19.  
    <dependency>
  20.  
    <groupId>org.springframework.cloud</groupId>
  21.  
    <artifactId>spring-cloud-starter-eureka</artifactId>
  22.  
    </dependency>
  23.  
    <dependency>
  24.  
    <groupId>de.codecentric</groupId>
  25.  
    <artifactId>spring-boot-admin-server</artifactId>
  26.  
    <version>1.4.5</version>
  27.  
    </dependency>
  28.  
    <dependency>
  29.  
    <groupId>de.codecentric</groupId>
  30.  
    <artifactId>spring-boot-admin-server-ui</artifactId>
  31.  
    <version>1.4.5</version>
  32.  
    </dependency>
  33.  
    </dependencies>
  • 注意版本号(1.5.2+1.5.7)

application.properties配置:

  1.  
    spring .application.name=admin-ui
  2.  
    info .version=@project.version@
  3.  
    server .port=8080
  4.  
     
  5.  
    eureka .client.serviceUrl.defaultZone=http://localhost:8888/eureka/

java代码:

  1.  
    @SpringBootApplication
  2.  
    @EnableDiscoveryClient
  3.  
    @EnableAdminServer
  4.  
    public class AdminApplication {
  5.  
     
  6.  
    public static void main(String[] args) {
  7.  
    SpringApplication.run(AdminApplication.class, args);
  8.  
    }
  9.  
    }

logback-spring.xml配置:

  1.  
    <?xml version="1.0" encoding="UTF-8"?>
  2.  
    <configuration>
  3.  
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
  4.  
    <jmxConfigurator/>
  5.  
    </configuration>

添加其他项目被监控

在被监控的服务pom.xml中增加:

  1.  
    <!--
  2.  
    spring-boot-admin-starter-client中包含的spring-boot-starter-actuator用于收集服务信息
  3.  
    <dependency>
  4.  
    <groupId>org.springframework.boot</groupId>
  5.  
    <artifactId>spring-boot-starter-actuator</artifactId>
  6.  
    </dependency>
  7.  
    -->
  8.  
    <dependency>
  9.  
    <groupId>de.codecentric</groupId>
  10.  
    <artifactId>spring-boot-admin-starter-client</artifactId>
  11.  
    <version>1.4.5</version>
  12.  
    </dependency>

application.properties增加:

  1.  
    # 关闭安全访问
  2.  
    management.security.enabled= false
  3.  
     
  4.  
    # 如果被监控的服务没有注册到服务中心,需要增加admin的地址
  5.  
    # spring.boot.admin.url=http://localhost:8888

增加logback-spring.xml:

  1.  
    <?xml version="1.0" encoding="UTF-8"?>
  2.  
    <configuration>
  3.  
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
  4.  
    <jmxConfigurator/>
  5.  
    </configuration>
  6.  
     
  7.  
     
  • 主控界面:

  • 单个服务的详情页面,其它不再赘述.

 转自:https://blog.csdn.net/u014320421/article/details/79708622

猜你喜欢

转载自www.cnblogs.com/dauber/p/9339745.html