Spring Boot提供的監控接口,例如:/health、/info等等,實際上除了以前提到的信息,還有其餘信息業須要監控:當前處於活躍狀態的會話數量、當前應用的併發數、延遲以及其餘度量信息。下面咱們來了解如何使用spring-boot-admin來監控咱們的系統。java
pom.xml
配置:spring
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.3.RELEASE</version> <relativePath/> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.4.5</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.4.5</version> </dependency> </dependencies>
application.properties
配置:
安全
spring.application.name=admin-ui info.version=@project.version@ server.port=8080 eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/
java代碼:
併發
@SpringBootApplication @EnableDiscoveryClient @EnableAdminServer public class AdminApplication { public static void main(String[] args) { SpringApplication.run(AdminApplication.class, args); } }
logback-spring.xml
配置:
app
<?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <jmxConfigurator/> </configuration>
在被監控的服務pom.xml
中增長:ide
<!-- spring-boot-admin-starter-client中包含的spring-boot-starter-actuator用於收集服務信息 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> --> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>1.4.5</version> </dependency>
application.properties
增長:
spring-boot
# 關閉安全訪問 management.security.enabled=false # 若是被監控的服務沒有註冊到服務中心,須要增長admin的地址 # spring.boot.admin.url=http://localhost:8888
增長logback-spring.xml
:
ui
<?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <jmxConfigurator/> </configuration>
主控界面: 項目源碼實例go: www.b12.com ,url
單個服務的詳情頁面,其它再也不贅述.spa