最近在找一個spring cloud的監控組件,要求粒度要到每一個接口的,hystrix dashboard顯然不適合,也不是這個應用場景。后來發現了spring boot admin這個神器,可以注冊到Eureka和spring cloud無縫整合,頁面AngularJS寫的還算湊合,里面包含有許多功能:
好了,不多說,直接上和eureka整合的代碼,它可以通過eureka注冊表里面的信息來對每一個服務進行監控。
1、構建service-admin工程,pom如下:
<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>com.lovnx</groupId> <artifactId>micro-service</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>service-admin</artifactId> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.7</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.4.6</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.4.6</version> </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>Camden.SR5</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>
2、啟動主類:
package com.lovnx;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.context.annotation.Configuration;import de.codecentric.boot.admin.config.EnableAdminServer;@Configuration@EnableAutoConfiguration@EnableDiscoveryClient@EnableAdminServerpublic class SpringBootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminApplication.class, args); }}
3、配置文件application.properties:
server.port=7088spring.application.name=service-admineureka.client.serviceUrl.defaultZone=http://localhost:7070/eureka/[email protected]@
4、logback.xml(實現日志級別修改功能):
<configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <jmxConfigurator/></configuration>
5、啟動:
6、注意:
如果要監控注冊到eureka的服務,必須要在這個服務里面引入:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
來開啟一些管理功能,且須在配置文件加入一句:
management.security.enabled=false
關閉安全驗證。
代碼托管:https://github.com/Lovnx/micro-service
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答
圖片精選