为springboot项目添加springboot-admin监控
我们知道spring-boot-actuator暴露了大量统计和监控信息的端点,spring-boot-admin
就是为此提供的监控项目。
先来看看大概会提供什么样的功能
从图中可以看出,主要内容都是由spring boot actuator来提供的。更多关于actuator的信息参见Springboot actuator
接下来,hello world时间。
server端
server端是一个单独的springboot项目,主要负责收集和展示监控指标,提供了ui page。
项目地址: https://github.com/Ryan-Miao/springboot-admin-demo
新建一个springboot项目,可以使用idea自带的spring initializr. 主要添加以下两个依赖,
<springboot.version>1.5.13.RELEASE</springboot.version>
<spring-boot-admin.version>1.5.7</spring-boot-admin.version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
</dependencies>
在启动类上添加@EnableAdminServer
在配置文件中设置服务地址,这里假设为8081
server.port=8081
启动。
client 端
client端是指我们正常的app,我们的spring boot项目就是。在原有的基础上添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
之后配置相关信息:
client端添加admin的url,这里暂时忽略spring security
spring:
boot:
admin:
url: http://localhost:8081
management:
security:
enabled: false
然后,启动我们的app。访问localhost:8081就可以看到文章开始图片里的信息了。
更多文档: https://codecentric.github.io/spring-boot-admin/1.5.0/#_what_is_spring_boot_admin
关注我的公众号

分类:
spring
标签:
springboot
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了