Spring Boot Actuator


执行器提供的主要功能 运行状况检查:您可以使用运行状况端点来检查正在运行的应用程序的状态。 通过HTTP / JMX进行监视和管理:Actuator支持HTTP端点以及Java管理扩展(JMX),以提供监视和管理应用程序的标准机制。

  • Logger:它提供了查看和更新​​日志级别的功能。
  • Metrics:Spring Boot Actuator为Micrometer提供依赖项管理和自动配置,Micrometer是支持众多监视系统的应用程序指标外观。
  • Auditing:Spring Security发挥作用后,Spring Boot Actuator具有一个灵活的审计框架,可发布事件(默认情况下,“身份验证成功”,“失败”和“访问被拒绝”异常)。此功能对于基于身份验证失败的报告和实施锁定策略非常有用。
  • Http Tracing:可以通过HttpTraceRepository在应用程序的配置中提供类型的bean来启用HTTP跟踪。为了方便起见,Spring Boot提供了一个InMemoryHttpTraceRepository用于存储最近100次请求-响应交换的跟踪的记录
  • 流程监控

将执行器启用到Spring Boot项目中 您可以通过包含以下依赖项将Actuator启用到Spring引导项目中。

//Gradle
org.springframework.boot:spring-boot-starter-actuator:2.3.1.RELEASE
//Maven
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>2.3.1.RELEASE</version>
</dependency>

执行器提供的端点报价 默认情况下,“健康”和“信息”端点已启用

1594526992538.gif

默认的公开端点。 其他端点是敏感的,不建议在没有安全性的情况下暴露于生产环境。在演示时,让我们公开所有API。

management.endpoints.web.exposure.include=*

包括和排除端点。

您甚至可以通过定义以下属性来包含或排除端点

# wild card to include/exclude all
management.endpoints.web.exposure.include=* 
management.endpoints.web.exposure.exclude=* 
# you can include specific properties like below
management.endpoints.web.exposure.include=env,beans
management.endpoints.web.exposure.exclude=heapdump

自定义管理服务器地址 您可以自定义管理服务器端口,这将帮助您定义端口的有限范围。

management.server.port=8081 management.server.address=127.0.0.1

公开自定义端点

带有@ReadOperation@WriteOperation或注释的任何方法都会@DeleteOperation通过JMX和HTTP自动公开。甚至您也可以使用@JmxEndpoint或公开特定于技术的终结点@WebEndpoint

在这里,我为您分享使用Spring Boot 2.x公开端点的示例

import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

@Component
@org.springframework.boot.actuate.endpoint.annotation.Endpoint(id = "say-hello")
public class Endpoint {

    @ReadOperation
    public String sayHello()
    {
        return "Hello World";
    }

}

简介:弹簧启动执行器是您可以在应用程序中添加的最佳库之一,从而可以更轻松地启用可用于生产的功能。它提供了可以在日常生产支持中使用的关键功能。


原文链接:http://codingdict.com