Spring Boot Admin (Spring Clould Admin) 官方文档重点内容中文翻译
GitHub地址
文章目录
- 1. Spring Boot Admin简介
- 2. 快速入门
- 2.1 配置Spring Boot Admin Server (SBA Server)
- 2.2 注册Client应用
- 2.1 Spring Boot Admin Client
- 2.2.2 Spring Cloud Discovery(注册发现)
- 3. Client客户端应用
- 3.5 Spring Boot Admin Client 配置文件
- 4. Spring Boot Admin Server
- 4.1 反向代理配置
- 4.2 其他配置选项
- 4.3 Spring Cloud Discovery注册发现
- 4.3.1 使用`SimpleDiscoveryClient`进行静态配置
- 4.3.2 其他DiscoveryClients
- 4.3.3 Converting ServiceInstances(略)
- 4.3.4 CloudFoundry(略)
- 4.4 集群
- 4.5 通知
- 4.5.1 邮件通知
- 4.5.2 PagerDuty通知(略)
- 4.5.3 OpsGenie通知(略)
- 4.5.4 Hipchat通知(略)
- 4.5.5 Slack通知(略)
- 4.5.6 Let's Chat通知(略)
- 4.5.7 Microsoft Team通知(略)
- 4.5.8Telegram通知(略)
- 4.5.9 Discord通知(略)
- 4.5.10 通知代理设置(略)
- 4.5.11 后面暂时全略
- 常见问题
- 启动报错(Correct the classpath of your application so that it contains a single, compatible version of )
- 加入Context-path后,无法找到actuator(404)
1. Spring Boot Admin简介
该社区项目为SpringBoot应用提供了监控接口。
Spring Boot Admin 提供了以下特性:
- 显示健康状况
- 显示指标详情,例如:
- JVM 和 内存指标
- micrometer.io指标
- 数据源指标
- 缓存指标
- 显示 build-info 数量
- 跟踪和下载日志文件
- 展示jvm情况和环境配置
- 展示spring boot配置文件
- 支持spring cloud的 evn-endpoint 和 refresh-endpoint
- 方便的管理日志级别
- 和JMX-beans交互
- 查看thread dump
- 查看http-traces
- 查看auditevents
- 查看http-endpoints
- 查看定时任务(Scheduled tasks)
- 管理session(spring-session)
- 查看 Flyway / Liquibase 数据库迁移
- 下载 heapdump
- 当状态改变的时候可以通知(通过e-mail, Slack, Hipchat等)
- 记录状态变化的事件日志
2. 快速入门
2.1 配置Spring Boot Admin Server (SBA Server)
首先,初始化一个Spring Boot应用,SBA Server就放在这个应用中:
- 增添Spring Boot Admin Server starter 依赖:
<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.3.1</version>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
- 在
Application
上增添@EnableAdminServer
注解
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {public static void main(String[] args) {SpringApplication.run(SpringBootAdminApplication.class, args);}
}
2.2 注册Client应用
要把你的应用注册到SBA Server上,你可以在pom中增加SBA Client,也可以使用Spring Cloud注册中心。
2.1 Spring Boot Admin Client
想要把应用注册在SBA Server中,需要在pom文件中include Spring Boot Admin Client。为了保证应用的安全,还要增加 spring-boot-starter-security
.
- 增添
spring-boot-admin-starter-client
依赖
<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId><version>2.3.1</version>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>
- 在
application.properties
中进行配置:
spring.boot.admin.client.url=http://localhost:8080 # SBA Server的URL
management.endpoints.web.exposure.include=* # 配置需要监控哪些指标
- 使被监控端(acuator endpoints)可用:
@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().permitAll() .and().csrf().disable();}
}
方便起见,直接禁用security
2.2.2 Spring Cloud Discovery(注册发现)
如果你使用了Spring Cloud Discovery,就不需要 SBA Client 了。只需要增加 DiscoveryClient到 SBA Server中,剩下的就会自动配置
- 增加
spring-cloud-starter-eureka
依赖
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- 增加
@EnableDiscoveryClient
开启发现
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class SpringBootAdminApplication {public static void main(String[] args) {SpringApplication.run(SpringBootAdminApplication.class, args);}@Configurationpublic static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().permitAll() .and().csrf().disable();}}
}
简单起见,这里禁用了security
- 告诉Eureka客户端去哪找到该服务注册
eureka: instance:leaseRenewalIntervalInSeconds: 10health-check-url-path: /actuator/healthmetadata-map:startup: ${random.int} #needed to trigger info and endpoint update after restartclient:registryFetchIntervalSeconds: 5serviceUrl:defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/management:endpoints:web:exposure:include: "*" endpoint:health:show-details: ALWAYS
spring-boot-admin-sample-eureka样例
3. Client客户端应用
… 不重要,省略
3.5 Spring Boot Admin Client 配置文件
具体配置详情
4. Spring Boot Admin Server
4.1 反向代理配置
假设你的SBA Server运行在方向代理的后面,你需要配置 spring.boot.admin.ui.public-url
。同时,如果反向代理终止了http连接,你可能也需要配置server.forward-headers-strategy=native
4.2 其他配置选项
其他配置选项
4.3 Spring Cloud Discovery注册发现
SBA Server可以使用 Spring Clouds 的Discovery Client
去发现应用。优点是,你不需要在Client端包含spring-boot-admin-starter-client
依赖。你只需要在SBA Server端增加一个DiscoveryClient
的实现,剩下的都会通过自动配置(AutoConfiguration)自动完成
4.3.1 使用SimpleDiscoveryClient
进行静态配置
Spring Cloud 提供了SimpleDiscoveryClient
,它允许你通过静态配置指定Client应用:
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter</artifactId>
</dependency>
spring:cloud:discovery:client:simple:instances:test:- uri: http://instance1.intern:8080metadata:management.context-path: /actuator- uri: http://instance2.intern:8080metadata:management.context-path: /actuator
4.3.2 其他DiscoveryClients
除了Eureka之外,SBA也支持其他注册中心,例如Zookeeper,Consul等。
4.3.3 Converting ServiceInstances(略)
4.3.4 CloudFoundry(略)
4.4 集群
SBA Server 支持通过Hazelcast
进行复制(replication)。当项目中有 HazelcastConfig-
或 HazelcastInstance-
的 Bean
时,它就会自动开启。你也可以配置Hazelcast
实例来使其持久化,以便重启也能保持状态。
- 增加
Hazelcast
依赖:
<dependency><groupId>com.hazelcast</groupId><artifactId>hazelcast</artifactId>
</dependency>
- 实例化一个
HazelcastConfig
:
@Bean
public Config hazelcastConfig() {// 该map用来存储事件// 这应该配置更可靠地持久化// 如果事件太多,Spring Boot Admin 会对其压缩MapConfig eventStoreMap = new MapConfig(DEFAULT_NAME_EVENT_STORE_MAP).setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.NONE).setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));// 该map用于对通知去重// 如果这个map中的数据丢失了,没事,因为多个实例会推送多次消息MapConfig sentNotificationsMap = new MapConfig(DEFAULT_NAME_SENT_NOTIFICATIONS_MAP).setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.LRU).setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));Config config = new Config();config.addMapConfig(eventStoreMap);config.addMapConfig(sentNotificationsMap);config.setProperty("hazelcast.jmx", "true");// WARNING: 这个配置是在本机搞一个集群,你需要根据实际需求进行改造.config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();tcpIpConfig.setEnabled(true);tcpIpConfig.setMembers(singletonList("127.0.0.1"));return config;
}
Hazelcast
相关配置
属性名 | 描述 | 默认值 |
---|---|---|
spring.boot.admin.hazelcast.enabled | 开启Hazelcast | true |
spring.boot.admin.hazelcast.event-store | 存储事件的Hazelcast-map的名称 | “spring-boot-admin-event-store” |
spring.boot.admin.hazelcast.sent-notifications | 去重的Hazelcast-map的名称 | “spring-boot-admin-sent-notifications” |
4.5 通知
4.5.1 邮件通知
邮件使用Thymeleaf
模板渲染的HTML邮件。要开启邮件通知,需要使用spring-boot-starter-mail
配置JavaMailSender
并且设置接收人。
- 增加
spring-boot-starter-mail
依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId>
</dependency>
- 配置
JavaMailSender
spring.mail.host=smtp.example.com
spring.boot.admin.notify.mail.to=admin@example.com
- 配置相关参数:
属性名 | 描述 | 默认值 |
---|---|---|
spring.boot.admin.notify.mail.enabled | 开启邮件通知 | true |
spring.boot.admin.notify.mail.ignore-changes | 忽略从一个状态到另一个状态的改变,多个以逗号分隔。格式为: “<from-status>:<to-status>” 支持通配符 | “UNKNOWN:UP” |
spring.boot.admin.notify.mail.template | Thymeleaf模板的路径 | “classpath:/META-INF/spring-boot-admin-server/mail/status-changed.html” |
spring.boot.admin.notify.mail.to | 邮件接收者列表,多个以逗号分隔 | “root@localhost” |
spring.boot.admin.notify.mail.cc | 邮件抄送人列表,多个以逗号分隔 | |
spring.boot.admin.notify.mail.from | 邮件发送人 | “Spring Boot Admin noreply@localhost” |
spring.boot.admin.notify.mail.additional-properties | 可以从模板访问的其他属性 |
4.5.2 PagerDuty通知(略)
4.5.3 OpsGenie通知(略)
4.5.4 Hipchat通知(略)
4.5.5 Slack通知(略)
4.5.6 Let’s Chat通知(略)
4.5.7 Microsoft Team通知(略)
4.5.8Telegram通知(略)
4.5.9 Discord通知(略)
4.5.10 通知代理设置(略)
4.5.11 后面暂时全略
常见问题
启动报错(Correct the classpath of your application so that it contains a single, compatible version of )
Description:An attempt was made to call the method org.springframework.beans.factory.ObjectProvider.orderedStream()Ljava/util/stream/Stream; but it does not exist. Its class, org.springframework.beans.factory.ObjectProvider, is available from the following locations:jar:file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-beans/5.0.13.RELEASE/spring-beans-5.0.13.RELEASE.jar!/org/springframework/beans/factory/ObjectProvider.classIt was loaded from the following location:file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-beans/5.0.13.RELEASE/spring-beans-5.0.13.RELEASE.jarAction:Correct the classpath of your application so that it contains a single, compatible version of org.springframework.beans.factory.ObjectProvider
原因:spring-boot-admin版本不合适
解决办法:更换合适的spring-boot-admin版本
加入Context-path后,无法找到actuator(404)
原因:加入context-path后,全局路径发生改变了,所以需要额外配置
解决方法:增加如下配置
eureka:instance:metadata-map:management:context-path: ${server.servlet.context-path}/actuatorstatusPageUrlPath: ${server.servlet.context-path}/actuator/infohome-page-url-path: ${server.servlet.context-path}health-check-url-path: ${server.servlet.context-path}/actuator/health
Spring Boot Admin (Spring Clould Admin) 官方文档重点内容中文翻译相关推荐
- pytest官方文档 6.2 中文翻译版(第十章):警告捕捉
从3.1版本开始,pytest会在整个测试执行的过程中自动的捕捉警告: # content of test_show_warnings.py import warningsdef api_v1():w ...
- Kafka 官方文档1(中文)
1.开始 Kafka 学习之旅 1.1 简介 "Apache Kafka is a distributed streaming platform" 这是 kafka 官网上给出的介 ...
- pytest官方文档 6.2 中文翻译版(第五章):pytest夹具:明确的,模块化的,可扩展的
软件测试夹具是用于初始化的测试功能的.它们提供了一个固定的基线,以便测试能够可靠地执行并产生一致的,可重复的结果.初始化可能会设置服务.状态或其他运行环境.测试函数可以通过参数访问测试夹具,通常在测试 ...
- voltDB官方文档第三章翻译
序:本文章是自己再网上查看VoltDB相关资料的时候没有找到太好的学习资料,就前去官方网站上翻译了一部分,约束于个人英语能力有限.实际记录下来的翻译只有第三章. 注:文章翻译自voltDB官方提供的学 ...
- pytest官方文档 6.2 中文翻译版(第一章):安装和入门指南
安装和入门指南 Python版本: Python 3.6, 3.7, 3.8, 3.9, PyPy3 平台: Linux and Windows PyPI 包名: pytest Documentati ...
- Spring Boot 2.0官方文档之 Actuator
https://blog.csdn.net/alinyua/article/details/80009435 前言:本文翻译自Spring Boot 2.0.1.RELEASE官方文档,该Spring ...
- Spring Boot 官方文档学习(一)入门及使用
Spring Boot 官方文档学习(一)入门及使用 个人说明:本文内容都是从为知笔记上复制过来的,样式难免走样,以后再修改吧.另外,本文可以看作官方文档的选择性的翻译(大部分),以及个人使用经验及问 ...
- hadoop官方文档_hadoop体系简介
hadoop核心 Apache Hadoop 项目有两个核心组件,被称为 Hadoop 分布式文件系统 (Hadoop Distributed File System, HDFS) 的文件存储,以及被 ...
- 喜大普奔!Django官方文档终于出中文版了
喜大普奔!Django官方文档终于出中文版了 文章来源:企鹅号 - Crossin的编程教室 昨天经 Sur 同学告知才发现,Django 官方文档居然支持中文了! 之所以让我觉得惊喜与意外,是因为: ...
最新文章
- Cascading(一)之日志解析
- [云炬创业基础笔记]第七张创业团队测试8
- 配置redis自启动脚本
- SAP Hybris的build callback和SAP ABAP的SGEN事务码
- 使用函数求最大公约数 pta_高中数学选修教材2-导数第6课时《函数的单调性与导数》教学设计...
- skywalking 安装_SkyWalking全链路追踪利器
- java的课程总结_Java课程总结
- jdk的ServiceLoader
- 【jQuery笔记Part2】01-jQuery显示隐藏切换动画侧边广告案例
- SQL经典50题练习
- origin调整纵坐标刻度值_Origin数据图坐标刻度值特殊标注的方法
- cpu控制器如何工作
- c语言other用法,other的用法总结
- directadmin安装多个php,DirectAdmin安装记录(2018更新)
- 2022年系统分析师综合知识考点整理
- 浅谈JdbcDaoSupport
- 在部队当程序员是什么体验?
- 【转载】我到底该不该继续交社保?
- ChatGPT聊天机器人如何发图片????
- access查询设计sol视图_选择查询-在access中如何建立一个选择查询只查询一个信?在access 爱问知识人...