Spring Boot Admin 可以对SpringBoot应用的各项指标进行监控,可以作为微服务架构中的监控中心来使用,本文将对其用法进行详细介绍。
SpringBoot应用可以通过Actuator来暴露应用运行过程中的各项指标,Spring Boot Admin通过这些指标来监控SpringBoot应用,然后通过图形化界面呈现出来。Spring Boot Admin不仅可以监控单体应用,还可以和Spring Cloud的注册中心相结合来监控微服务应用。
Spring Boot Admin 可以提供应用的以下监控信息:
-
监控应用运行过程中的概览信息;
-
度量指标信息,比如JVM、Tomcat及进程信息;
-
环境变量信息,比如系统属性、系统环境变量以及应用配置信息;
-
查看所有创建的Bean信息;
-
查看应用中的所有配置信息;
-
查看应用运行日志信息;
-
查看JVM信息;
-
查看可以访问的Web端点;
-
查看HTTP跟踪信息。
这里我们创建一个admin-server模块来作为监控中心演示其功能。
在pom.xml中添加相关依赖:
org.springframework.boot
spring-boot-starter-web
de.codecentric
spring-boot-admin-starter-server
在application.yml中进行配置:
server:
port: 9301
spring:
application:
name: admin-server
在启动类上添加@EnableAdminServer来启用admin-server功能:
@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
这里我们创建一个admin-client模块作为客户端注册到admin-server。
在pom.xml中添加相关依赖:
org.springframework.boot
spring-boot-starter-web
de.codecentric
spring-boot-admin-starter-client
在application.yml中进行配置:
server:
port: 9305
spring:
application:
name: admin-client
boot:
admin:
client:
配置admin-server地址
url: http://localhost:9301
management:
endpoints:
web:
exposure:
include: ‘*’
endpoint:
health:
show-details: always
添加开启admin的日志监控
logging:
file: admin-client.log
启动admin-server和admin-client服务。
访问如下地址打开Spring Boot Admin的主页:http://localhost:9301
点击wallboard按钮,选择admin-client查看监控信息;
监控信息概览;
度量指标信息,比如JVM、Tomcat及进程信息;
环境变量信息,比如系统属性、系统环境变量以及应用配置信息;
查看所有创建的Bean信息;
查看应用中的所有配置信息;
查看日志信息,admin-client模块的applicaiton.yml需要添加以下配置才能开启;
logging:
#添加开启admin的日志监控
file: admin-client.log
查看JVM信息;
查看可以访问的Web端点;
Spring Boot Admin结合Spring Cloud 注册中心使用,只需将admin-server和注册中心整合即可,admin-server 会自动从注册中心获取服务列表,然后挨个获取监控信息。这里以Eureka注册中心为例来介绍下该功能。
修改admin-server
在pom.xml中添加相关依赖:
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
在application-eureka.yml中进行配置,只需添加注册中心配置即可:
server:
port: 9301
spring:
application:
name: admin-server
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
在启动类上添加@EnableDiscoveryClient来启用服务注册功能:
@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
修改admin-client
在pom.xml中添加相关依赖:
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
在application-eureka.yml中进行配置,删除原来的admin-server地址配置,添加注册中心配置即可:
server:
port: 9305
spring:
application:
name: admin-client
boot:
admin:
client:
配置admin-server地址
url: http://localhost:9301
management:
endpoints:
web:
exposure:
include: ‘*’
endpoint:
health:
show-details: always
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
添加开启admin的日志监控
logging:
file: admin-client.log
在启动类上添加@EnableDiscoveryClient来启用服务注册功能:
@EnableDiscoveryClient
@SpringBootApplication
public class AdminClientApplication {
public static void main(String[] args) {
SpringApplication.run(AdminClientApplication.class, args);
}
}
功能演示
启动eureka-server,使用application-eureka.yml配置启动admin-server,admin-client;
查看注册中心发现服务均已注册:http://localhost:8001/
查看Spring Boot Admin 主页发现可以看到服务信息:http://localhost:9301
我们可以通过给admin-server添加Spring Security支持来获得登录认证功能。
创建admin-security-server模块
在pom.xml中添加相关依赖:
org.springframework.boot
spring-boot-starter-security
org.springframework.boot
spring-boot-starter-web
de.codecentric
spring-boot-admin-starter-server
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
最后
金三银四马上就到了,希望大家能好好学习一下这些技术点
学习视频:
大厂面试真题:
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
[外链图片转存中…(img-eFmYiRkP-1713300214138)]
[外链图片转存中…(img-gU7SO8rB-1713300214138)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
最后
金三银四马上就到了,希望大家能好好学习一下这些技术点
学习视频:
[外链图片转存中…(img-Vj96aACd-1713300214138)]
大厂面试真题:
[外链图片转存中…(img-FXVoFbTI-1713300214139)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!