最近在做新系统的框架搭建,想要给系统加一个监控应用的模块,感觉 spring boot admin 不错,就把他集成进来了。做个简单总结
我这里采用的是 maven 多module 形式,新起 一个spring boot admin 微服务,能后在其他服务器中导入相关jar 和配置就可以了,简单方便。
新建spring boot admin 服务端
新起一个叫 admin 的 module
其中 pom.xml 需要导入如下依赖
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
配置文件
server:
port: 10005
spring:
application:
name: admin
aop:
proxyTargetClass: true
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
hostname: ${spring.cloud.client.ip-address}
client:
service-url:
defaultZone: http://127.0.0.1:10001/eureka/
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
启动类, 加入 EnableAdminServer 注解
@SpringBootApplication
@EnableAdminServer
public class AdminApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}
}
原有微服务改造
很简单就两步
- 引入 actuator 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- 增加如下配置
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
到这整合完毕,启动项目 打开浏览器 访问admin 项目 (127.0.0.1:1005)就能看到效果了
问题:
- 服务器启动成功,也能正常访问,但是状态还是显示 down
原因: 只要有一个监控内容为down,改节点就为down ,可得点开详情,在右侧查看具体down 的服务,能后进行排查