【监控篇】Spring Boot Admin 监控 Spring Boot 应用健康状况

导读:本篇文章讲解 【监控篇】Spring Boot Admin 监控 Spring Boot 应用健康状况,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

Spring Boot Admin

Spring Boot Admin 是一个开源的社区项目,可以监控所有 Spring Boot 应用的健康状况,提供实时警报功能。Spring Boot Admin 可以监控 Spring Boot 单机或集群项目。

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

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

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

文档地址:https://codecentric.github.io/spring-boot-admin/2.5.1/#getting-started

Spring Boot Admin Server

1.引入依赖

<!-- admin-server -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.5.6</version>
</dependency>

2.配置启动 Admin Server

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAdminServer
public class MingYueSpringbootAdminApplication {

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

3.修改配置文件

server:
  port: 9000

4.启动服务端

访问:http://127.0.0.1:9000/applications

Spring Boot Admin Client

1.引入依赖

<!-- admin-client -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.5.6</version>
</dependency>

2.修改配置文件

spring:
  boot:
    admin:
      client:
        url: http://127.0.0.1:9000

3.启动客服端

2022-04-22 09:56:39.040  INFO 45632 --- [gistrationTask1] d.c.b.a.c.r.ApplicationRegistrator       : Application registered itself as 2303b5437928

4.查看服务端注册信息

和启动日志的 ID 相同,Application registered itself as 2303b5437928

image-20220422095858509

配置属性

更多详细介绍可以查看:http://c.biancheng.net/view/5509.html 和官网文档

Server 配置属性详解

属性 描述 默认值
spring.boot.admin.context-path 上下文路径在应为Admin Server的静态资产和API提供服务的路径的前面加上前缀。相对于Dispatcher-Servlet /
spring.boot.admin.monitor.status-interval 更新client端状态的时间间隔,单位是毫秒 10000
spring.boot.admin.monitor.status-lifetime client端状态的生命周期,该生命周期内不会更新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”

Client 配置属性详解

属性 描述 默认值
spring.boot.admin.client.enabled 启用Spring Boot Admin Client true
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.* 标记作为要与此实例相关联的键值对

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/78332.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!