(十四)SpringBoot2.0整合Actuator監控管理及Admin-UI分佈式微服務監控中心

一. Actuator監控應用

Actuator是spring boot的一個附加功能,可幫助你在應用程序生產環境時監視和管理應用程序。可以使用HTTP的各種請求來監管,審計,收集應用的運行情況.特別對於微服務管理十分有意義.缺點:沒有可視化界面。

1.1 Maven依賴

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

1.2 yml配置

###通過下面的配置啓用所有的監控端點,默認情況下,這些端點是禁用的;
management:
  endpoints:
    web:
      exposure:
        include: "*"
###接口 相當在配置文件中,配置相關info開頭的配置信息
info:
  hszsd: 合石招商貸
  name: 何金榮

1.3 Actuator訪問路徑

通過actuator/+端點名就可以獲取相應的信息。

路徑 作用
/actuator/beans 顯示應用程序中所有Spring bean的完整列表。
/actuator/configprops 顯示所有配置信息。
/actuator/env 陳列所有的環境變量。
/actuator/mappings 顯示所有@RequestMapping的url整理列表。
/actuator/health 顯示應用程序運行狀況信息 up表示成功 down失敗
/actuator/info 查看自定義應用信息

1.4 啓動

http://localhost:8080/actuator/info
可以訪問到自己定義的字段屬性。

二. Admin-UI分佈式微服務監控中心

Admin-UI基於actuator實現能夠返回界面展示監控信息

2.1 Admin-UI-Server

2.1.1 maven依賴

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.3.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<properties>
		<java.version>1.8</java.version>
		<spring-boot-admin.version>2.1.3</spring-boot-admin.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>de.codecentric</groupId>
			<artifactId>spring-boot-admin-starter-server</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webflux</artifactId>
		</dependency>

2.1.2 yml配置

server:
  port: 8800
spring:
  application:
    name: admin-ui-server

2.1.3 啓動類配置

@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class Springboot2008AdminUiServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(Springboot2008AdminUiServerApplication.class, args);
	}

}

2.2 Admin-UI-Client

2.2.1 maven依賴

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.3.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<properties>
		<java.version>1.8</java.version>
		<spring-boot-admin.version>2.1.3</spring-boot-admin.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<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.jolokia</groupId>
			<artifactId>jolokia-core</artifactId>
		</dependency>
		<dependency>
			<groupId>com.googlecode.json-simple</groupId>
			<artifactId>json-simple</artifactId>
			<version>1.1</version>
		</dependency>

2.2.2 yml配置

spring: ##配置client 註冊到admin ui 平臺
  boot:
    admin:
      client:
        url: http://localhost:8800
  application:
    name: admin-ui-client
server:
  port: 8801
### 開放所有的監控接口監控權限  
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always

2.2.3 啓動類配置

@SpringBootApplication
public class Springboot2008AdminUiClientApplication {

	public static void main(String[] args) {
		SpringApplication.run(Springboot2008AdminUiClientApplication.class, args);
	}

}

三. 源碼地址

https://gitee.com/hejr.cn.com/SpringBoot2.0_2019/tree/master/springboot2_008_admin_ui_client
https://gitee.com/hejr.cn.com/SpringBoot2.0_2019/tree/master/springboot2_008_admin_ui_server

下一篇:(十五)SprinBoot2.0性能優化

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章