您好,登錄后才能下訂單哦!
Spring boot實現監控Actuator-Admin的方法?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
Actuator是監控管理,不過沒有可視化,這里就引入了admin-ui來解決Spring Boot Admin 分為Client端和Server端Client端是客戶端Server端是spring-boot-admin來監控client的.先來一個Client客戶端代碼;
<?xml version="1.0" encoding="UTF-8"?> <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> <artifactId>spring-boot-demo-admin-client</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>spring-boot-demo-admin-client</name> <description>Demo project for Spring Boot</description> <parent> <groupId>com.xkcoding</groupId> <artifactId>spring-boot-demo-admin</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.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-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <finalName>spring-boot-demo-admin-client</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
application.yml文件,注意這里的url一定跑配置到Server的路徑,不然找不到,有點類型erkura的注冊中心地址.
server: port: 8081 servlet: context-path: /demo spring: application: # Spring Boot Admin展示的客戶端項目名,不設置,會使用自動生成的隨機id name: spring-boot-demo-admin-client boot: admin: client: # Spring Boot Admin 服務端地址 url: "http://localhost:8080/" instance: metadata: # 客戶端端點信息的安全認證信息 user.name: ${spring.security.user.name} user.password: ${spring.security.user.password} security: user: name: xkcoding password: 123456 management: endpoint: health: # 端點健康情況,默認值"never",設置為"always"可以顯示硬盤使用情況和線程情況 show-details: always endpoints: web: exposure: # 設置端點暴露的哪些內容,默認["health","info"],設置"*"代表暴露所有可訪問的端點 include: "*"
Java文件就隨便暴露個接口就行
package com.xkcoding.admin.client.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /** * <p> * 首頁 * </p> * * @package: com.xkcoding.admin.client.controller * @description: 首頁 * @author: yangkai.shen * @date: Created in 2018/10/8 2:15 PM * @copyright: Copyright (c) 2018 * @version: V1.0 * @modified: yangkai.shen */ @RestController public class IndexController { @GetMapping(value = {"", "/"}) public String index() { return "This is a Spring Boot Admin Client."; } }
接下來是Server服務端,作為監控平臺使用pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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> <artifactId>spring-boot-demo-admin-server</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>spring-boot-demo-admin-server</name> <description>Demo project for Spring Boot</description> <parent> <groupId>com.xkcoding</groupId> <artifactId>spring-boot-demo-admin</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.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-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <finalName>spring-boot-demo-admin-server</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
application.yml
server: port: 8080
運行服務端地址,發現已經檢測到了注冊過的客戶端
可以看到客戶端的信息
http追蹤可以看到請求
關于Spring boot實現監控Actuator-Admin的方法問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。