序言
随着開發周期的推移,項目會不斷變大,切分出的服務也會越來越多,這時一個個的微服務構成了錯綜複雜的系統。對于各個微服務系統的健康狀态、會話數量、并發數、服務資源、延遲等度量資訊的收集就成為了一個挑戰。Spring Boot Admin 應運而生,它正式基于這些需求開發出的一套功能強大的監控管理系統。
此文章僅限入門 SpringCloud版本為 Greenwich
Spring Boot Admin 有兩個角色組成,一個是 Spring Boot Admin Server,一個是 Spring Boot Admin Client。
版本管理
由于Spring Boot Admin 不受spring-cloud-dependencies 版本管理的控制,是以我們要加入他自己的一個版本控制
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>2.1.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
然後就ok了
服務端
首先加入依賴
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<!--eureka client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--鍊路追蹤-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
</dependencies>
然後是啟動類
@SpringBootApplication
@EnableAdminServer
public class SbaApplication {
public static void main(String[] args) {
SpringApplication.run(SbaApplication.class, args);
}
}
在然後就是yml
server:
port: 8088
spring:
application:
name: spring-cloud-action-sba
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: '*'
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${spring.application.instance_id:${server.port}}
hostname: localhost
client:
service-url:
# defaultZone 千萬别寫成 default-zone
defaultZone: http://${eureka.instance.hostname}:8761/eureka/
在
application.yml
檔案中配置
actuator
的相關配置,其中
info
開頭的屬性,就是通路
info
端點中顯示的相關内容,值得注意的是
Spring Boot2.x
中,預設隻開放了
info、health
兩個端點,剩餘的需要自己通過配置
management.endpoints.web.exposure.include
屬性來加載(有
include
自然就有
exclude
,不做詳細概述了)。如果想單獨操作某個端點可以使用
management.endpoint.端點.enabled
屬性進行啟用或禁用 。
management:
endpoints:
web:
exposure:
exclude: env,beans
include: '*'
在yml中有特殊的含義,是以如果想使用include或者exclude包含所有的端點時要加上引号,如下示例:
management:
endpoints:
web:
exposure:
include: '*'
這樣一個Spring Boot Admin 的服務端就已經弄好了。在sc 中隻要服務注冊進 注冊中心中 sba 就可以拉取到資訊啦。
此文章僅限入門,切記啊不會用找不到多去官網看文檔!