Spring boot admin可视化服务监控

本文详细介绍了如何使用Spring Boot Admin进行可视化服务监控,包括admin-service和admin-client的集成,以及实时日志查看和admin-server的通知扩展功能。通过启用@EnableAdminServer,配置安全框架,以及设置客户端的日志路径,可以实现对Spring Boot应用的全面监控。此外,文章还揭示了实时日志查看的实现原理,并提供了admin-server自定义通知功能的实现思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2.3.0版本的文档

作用

监控spring boot应用的可视化组件。已经内置了漂亮的ui界面。

集成

admin分为两个组件:service和client;版本选择需要与spring boot版本对应,我选择的版本是2.3.0

admin-service 服务

1、创建一个项目作为监控服务端:service-monitor,maven依赖如下

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- spring boot admin:包含了ui依赖和server依赖 -->
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-server</artifactId>
        <version>2.3.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
</dependencies>

既然是监控服务,那么就需要保障安全,不能“裸奔”让所有人都能访问,所以需要引入security安全框架保障安全。

2、使用@EnableAdminServer注解激活服务

@SpringBootApplication
// 启动admin
@EnableAdminServer
public class ServiceMonitorApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceMonitorApplication.class, args);
    }
}

3、security安全配置

官方文档有详细的讲解和代码(我的这个配置就是照搬的)

@Configuration(proxyBeanMethods = false)
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private AdminServerProperties adminServer;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // 配置认证成功的处理类,绑定 adminServer 的目标地址
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthe
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值