SpringBoot四大核心特性(四)

actuator

Spring Boot包括许多附加特性,帮助您在将应用程序推向生产环境时监视和管理应用程序。您可以选择通过使用HTTP端点或使用JMX来管理和监视应用程序。审计、运行状况和指标收集也可以自动应用于应用程序。

Spring Boot Actuator 的关键特性是在应用程序里提供众多 Web 端点,通过它们了解应用程序运行时的内部状况。

有了 Actuator,你可以知道 Bean 在 Spring 应用程序上下文里是如何组装在一起的,掌握应用程序可以获取的环境属性信息
在 spring-boot 项目中,添加 actuator 的一个 starter.


	org.springframework.boot
	spring-boot-starter-actuator


启动服务之后,可以通过下面这个地址看到 actuator 提供的所有 Endpoint 地址: http://localhost:8080/actuator

有一些 Endpoint 是不能访问的,涉及到安全问题。如 果想开启访问那些安全相关的url ,可以在application.xml 中配置,开启所有的 endpoint: management.endpoints.web.exposure.include=*

默认所有的endpints都是开启的,除了shutdown之外,启用shutdown的endpoint: management.endpoint.shutdown.enabled=true

health

可以使用 health 检查正在运行的应用程序的状态。当生产系统出现故障时,监控软件通常会用它来提醒用户。health endpoint 公开的信息依赖于management.endpoint.health.show-details和management.endpoint.health.show-components。可配置以下值之一的显示组件属性:

Name Description

never

Details are never shown.default value.

when-authorized

Details are only shown to authorized users. Authorized roles can be configured using management.endpoint.health.roles.

always

Details are shown to all users.

health information 从HealthContributorRegistry的内容收集(默认情况下,在您的ApplicationContext中定义的所有HealthContributor实例)。Spring Boot包括许多自动配置的HealthContributors,您也可以自己编写。

以下HealthIndicators是由Spring Boot在适当的时候自动配置的:

Name Description

你可能感兴趣的:(SpringBoot四大核心特性(四))