Spring Boot Admin开源监控系统

Spring Boot Admin 提供了一个简单的管理界面,它用于管理系统中运行的Spring Boot应用程序。

它的功能非常丰富,主要包括以下方面:

  • 查看健康状态
  • 查看JVM与内存指标
  • 查看计数器与计量表指标
  • 查看数据源指标
  • 查看缓存指标
  • 查看系统构建信息
  • 查看并下载日志文件
  • 查看JVM系统属性与环境变量
  • 查看线程堆栈信息
  • 查看调用轨迹信息
  • 查看状态变更日志
  • 修改日志级别管理(基于Logback)
  • 修改JMX参数
  • 下载JVM堆内存文件
  • 通知状态变更(邮件或即时通信工具)

项目地址:

https://github.com/codecentric/spring-boot-admin

实践

(1)服务端

https://start.spring.io 中创建项目 adminserver,下载。

添加依赖:

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.1.1</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

启动类上添加注解:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;

import de.codecentric.boot.admin.server.config.EnableAdminServer;

@Configuration
@EnableAutoConfiguration
@EnableAdminServer
@SpringBootApplication
public class AdminserverApplication {

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

}

启动项目:

$ mvn spring-boot:run

访问 http://localhost:8080

1527923-0bd01e61e0b83793.jpg
image

现在还没有项目注册进来,所以应用数量为0。

(2)客户端

https://start.spring.io 中创建项目 adminclient,下载。

添加依赖:

<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>
    <version>2.1.1</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

添加配置类:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
public class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll()  
            .and().csrf().disable();
    }
}

配置文件中添加:

server.port=8081
spring.boot.admin.client.url=http://localhost:8080  
spring.boot.admin.client.name=HelloService
management.endpoints.web.exposure.include=*

启动项目:

$ mvn spring-boot:run

再次访问admin控制台页面 http://localhost:8080

1527923-2214c301b63cee96.jpg
image

可以看到应用数量已经为1,点击查看详情:

1527923-3cb10267f45eae9d.jpg
image

详情页面有丰富的监控信息。

springboot admin 配置完成。

猜你喜欢

转载自blog.csdn.net/weixin_34233618/article/details/87088414