Actuator是spring boot的一个附加功能,可帮助你在应用程序生产环境时监视和管理应用程序。可以使用HTTP的各种请求来监管,审计,收集应用的运行情况.特别对于微服务管理十分有意义.缺点:没有可视化界面。
整合过程如下:
1.Admin Server 服务端搭建
(1).pom文件引入
<!--actuator 监控中心服务端-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.3.0</version>
</dependency>
<!--actuator 监控中心-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</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>
<!-- https://mvnrepository.com/artifact/io.projectreactor.addons/reactor-extra -->
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-extra</artifactId>
<version>3.3.3.RELEASE</version>
</dependency>
(2)启动类
@SpringBootApplication
@EnableAdminServer
public class SpringbootVueApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootVueApplication.class, args);
}
}
这里需要注意maven引入包可能报错,我搭建springboot是2.3.3.RELEASE 但spring-boot-admin-starter-server maven仓库是没有此包,如果引用2.2.0这些版本会报错
Springboot监控中心报错A attempt was made to call the method reactor.retry.Retry.retryMax(I)Lreactor/ret)
不能难看出是根本原因就是pom.xml文件中版本依赖有问题,必须同版本。
2.Admin Server 客户端搭建
(1).pom文件引入
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
注意,客户端与服务端引入的版本必须一致,不然可能出现注册服务失败
(2)application.yml配置
##配置admin actuator监控中心的服务器地址
spring:
boot:
admin:
client:
url: http://localhost:8080
instance:
#client地址
service-base-url: http://localhost:${server.port}
## 配置服务器启动端口
server:
port: 9000
###通过下面的配置启用所有的监控端点,默认情况下,这些端点是禁用的;
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
# 是否展示健康检查详情
show-details: ALWAYS
(3)启动类
@SpringBootApplication
public class AdminuiClientApplication {
public static void main(String[] args) {
SpringApplication.run(AdminuiClientApplication.class, args);
}
}
3.运行成功结果
搭建很简单,出现主要问题maven 引入jar包失败问题
@EnableAdminServer注解报错,我们也添加了spring-boot-admin-starter-server的引入,那就是我们对应的springboot版本没有对应jar,造成下载失败,须自定义版本号。
版权声明:本文为weixin_42933886原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。