Spring Boot 2.X(十七):应用监控之 Spring Boot Admin 使用及配置

Admin 简介

Spring Boot Admin 是 Spring Boot 应用程序运行状态监控和管理的后台界面。最新UI使用vue.js重写里。

Spring Boot Admin 为已注册的应用程序提供了丰富的监控运维功能。如下:

  • 显示健康状况
  • 显示应用运行时的详细信息,如:JVM 和内存指标等
  • 计数器和测量指标
  • 数据源度量
  • 缓存度量
  • 跟踪和下载日志文件
  • 查看 jvm 系统和环境属性
  • 一键管理loglevel
  • 管理执行 JMX-beans
  • 查看线程转储
  • 查看跟踪信息
  • Hystrix-Dashboard集成(2.X版本已删除集成)
  • 下载 heapdump
  • 状态更改通知(支持:电子邮件、Slack、Hipchat等)
  • 状态更改事件日志(非永久性)

更多可以通过考文档详细了解。

Admin 使用及配置

Spring Boot Admin 服务端

项目依赖
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
	<!-- admin-server -->
		<dependency>
			<groupId>de.codecentric</groupId>
			<artifactId>spring-boot-admin-starter-server</artifactId>
			<version>2.1.6</version>
		</dependency>
配置启动 Admin Server
@SpringBootApplication
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {

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

}
application.properties 配置
server.port=9000
spring.application.name=Spring Boot Admin Web
测试

启动项目,通过浏览器访问 http://127.0.0.1:9000

Spring Boot Admin 客户端

这里以上面是 Spring Boot Actuator 项目为例

项目依赖
<!-- admin-client -->
		<dependency>
			<groupId>de.codecentric</groupId>
			<artifactId>spring-boot-admin-starter-client</artifactId>
			<version>2.1.6</version>
		</dependency>
application.properties 配置
#设置 Admin Server 地址
server.port=8080
spring.application.name=Spring Boot Actuator Demo
spring.boot.admin.client.url=http://127.0.0.1:9000
测试

启动项目,通过浏览器访问 http://127.0.0.1:9000,我们会看到 Spring Boot Admin 的管理界面中 applications 会显示相应的客户端应用,点击应用进入详细的监控界面。


Spring Boot Admin 配置属性

Spring Boot Admin Server 配置属性详解
属性描述默认值
spring.boot.admin.context-path上下文路径在应为Admin Server的静态资产和API提供服务的路径的前面加上前缀。相对于Dispatcher-Servlet/
spring.boot.admin.monitor.status-interval更新client端状态的时间间隔,单位是毫秒10000
spring.boot.admin.monitor.status-lifetimeclient端状态的生命周期,该生命周期内不会更新client状态,单位是毫秒10000
spring.boot.admin.monitor.connect-timeout查询client端状态信息时的连接超时,单位是毫秒2000
spring.boot.admin.monitor.read-timeout查询client端状态信息时的读取超时时间,单位是毫秒10000
spring.boot.admin.monitor.default-retries失败请求的默认重试次数。Modyfing请求(PUT,POST,PATCH,DELETE)将永远不会重试0
spring.boot.admin.monitor.retries.*键值对,具有每个endpointId的重试次数。默认为默认重试。Modyfing请求(PUT,POST,PATCH,DELETE)将永远不会重试
spring.boot.admin.metadata-keys-to-sanitize要被过滤掉的元数据(当与正则表达式相匹配时,这些数据会在输出的json数据中过滤掉)“.password " , " . ∗ s e c r e t ", ".*secret ",".secret”, “.*key " , " . ", ". ",".token " , " . c r e d e n t i a l s . " , " . ∗ v c a p s e r v i c e s ", ".credentials.", ".*vcap_services ",".credentials.",".vcapservices
spring.boot.admin.probed-endpoints要获取的client的端点信息“health”, “env”, “metrics”, “httptrace:trace”, “threaddump:dump”, “jolokia”, “info”, “logfile”, “refresh”, “flyway”, “liquibase”, “heapdump”, “loggers”, “auditevents”
spring.boot.admin.instance-proxy.ignored-headers向client发起请求时不会被转发的headers信息“Cookie”, “Set-Cookie”, “Authorization”
spring.boot.admin.ui.public-url用于在ui中构建基本href的基本URL如果在反向代理后面运行(使用路径重写),则可用于进行正确的自我引用。如果省略了主机/端口,将从请求中推断出来
spring.boot.admin.ui.brand导航栏中显示的品牌<img src="assets/img/icon-spring-boot-admin.svg"><span>Spring Boot Admin</span>
spring.boot.admin.ui.title页面标题“Spring Boot Admin”
spring.boot.admin.ui.favicon用作默认图标的图标,用于桌面通知的图标“assets/img/favicon.png”
spring.boot.admin.ui.favicon-danger当一项或多项服务关闭并用于桌面通知时,用作网站图标“assets/img/favicon-danger.png”
Spring Boot Admin Client 配置属性详解
属性描述默认值
spring.boot.admin.client.enabled启用Spring Boot Admin Clienttrue
spring.boot.admin.client.url要注册的server端的url地址。如果要同时在多个server端口注册,则用逗号分隔各个server端的url地址
spring.boot.admin.client.api-path管理服务器上注册端点的Http路径“instances”
spring.boot.admin.client.username如果server端需要进行认证时,该属性用于配置用户名
spring.boot.admin.client.password如果server端需要进行认证时,该属性用于配置密码
spring.boot.admin.client.period重复注册的时间间隔(以毫秒为单位)10000
spring.boot.admin.client.connect-timeout连接注册的超时时间(以毫秒为单位)5000
spring.boot.admin.client.read-timeout读取注册超时(以毫秒为单位)5000
spring.boot.admin.client.auto-registration如果设置为true,则在应用程序准备就绪后会自动安排注册应用程序的定期任务true
spring.boot.admin.client.auto-deregistration当上下文关闭时,切换为在Spring Boot Admin服务器上启用自动解密。如果未设置该值,并且在检测到正在运行的CloudPlatform时,该功能处于活动状态null
spring.boot.admin.client.register-once如果设置为true,则客户端将仅向一台管理服务器注册(由定义spring.boot.admin.instance.url);如果该管理服务器出现故障,将自动向下一个管理服务器注册。如果为false,则会向所有管理服务器注册true
spring.boot.admin.client.instance.health-url要注册的health-url地址。如果可访问URL不同(例如Docker),则可以覆盖。在注册表中必须唯一默认该属性值与management-url 以及endpoints.health.id有关。比如工程中该值为:healthUrl=http://127.0.0.1:8080/actuator/health,其中http://127.0.0.1:8080/actuator是management-url,health是endpoints.health.id
spring.boot.admin.client.instance.management-base-url用于计算要注册的管理URL的基本URL。该路径是在运行时推断的,并附加到基本URL默认该属性值与management.port, service-url 以及server.servlet-path有关,如工程中该值为http://127.0.0.1:8080,其中8080端口是配置的获取actuator信息的端口。127.0.0.1是设置的service-url值,如果没有设置service-url的话,则为配置的server.servlet-path值(项目的启动路径)
spring.boot.admin.client.instance.management-url要注册的management-url。如果可访问的URL不同(例如Docker),则可以覆盖默认该属性值与management-base-url 和 management.context-path两个属性值有关,如 managementUrl=http://127.0.0.1:8080/actuator,其中http://127.0.0.1:8080为management-base-url,/actuator是management.context-path
spring.boot.admin.client.instance.service-base-url用于计算要注册的服务URL的基本URL。该路径是在运行时推断的,并附加到基本URL默认该属性值与hostname, server.port有关,如http://127.0.0.1:8080,其中8080端口是配置的server.port。127.0.0.1是client所在服务器的hostname
spring.boot.admin.client.instance.service-url要注册的服务网址。如果可访问的URL不同(例如Docker),则可以覆盖默认值是基于service-base-url 和 server.context-path进行赋值
spring.boot.admin.client.instance.name要注册的名称默认值是配置的spring.application.name的值,如果没有配置该属性的话,默认值是spring-boot-application
spring.boot.admin.client.instance.prefer-ip在猜测的网址中使用ip地址而不是主机名。如果设置了server.address/ management.address,它将被使用。否则,InetAddress.getLocalHost()将使用从返回的IP地址false
spring.boot.admin.client.instance.metadata.*要与此实例相关联的元数据键值对
spring.boot.admin.client.instance.metadata.tags.*标记作为要与此实例相关联的键值对

示例代码

github

码云

文档参考

https://codecentric.github.io/spring-boot-admin/2.1.6/#faqs

非特殊说明,本文版权归 朝雾轻寒 所有,转载请注明出处.

原文标题:Spring Boot 2.X(十七):应用监控之 Spring Boot Admin 使用及配置

原文地址: https://www.zwqh.top/article/info/26

如果文章对您有帮助,请扫码关注下我的公众号,文章持续更新中…

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码森林

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值