Spring boot 监控Actuator-Admin
Actuator是监控管理,不过没有可视化,这里就引入了admin-ui来解决
Spring Boot Admin 分为Client端和Server端
Client端是客户端
Server端是spring-boot-admin来监控client的.
先来一个Client客户端代码;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <?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的注册中心地址.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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文件就随便暴露个接口就行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <?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
1 2 | server: port: 8080 |
运行服务端地址,发现已经检测到了注册过的客户端

可以看到客户端的信息
http追踪可以看到请求
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决