40、springboot——运行状态监控使用Actuator

Spring Boot Actuator 提供了运行状态监控的功能 Actuator 监控数据可以通过阻REST
远程 shell 和JMX方式获得。我 首先来介绍通过 REST 方式查看 Actuator 的节点的方法,这
种是最常见且简单的方法。

通过执行器端点,您可以监控应用程序并与之交互。Spring Boot包含许多内置端点,允许您

添加自己的端点。例如, health端点提供基本的应用程序健康信息。

可以启用或禁用每个端点。它控制是否创建端点并且其bean存在于应用程序上下文中。要进行

远程访问,还必须通过JMX或HTTP公开端点 。大多数应用程序选择HTTP,其中端点的ID

以及前缀/actuator 映射到URL。例如,默认情况下,health端点映射到/actuator/health

官方文档地址:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

1、新建工程添加依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2.springboot2.x的配置

server.port=8009
management.server.port=8083
#开放所有页面节点  默认只开启了health、info两个节点
management.endpoints.web.exposure.include=*

#actuator端口

#修改访问路径  2.0之前默认是/   2.0默认是 /actuator  可以通过这个属性值修改
#management.endpoints.web.base-path: /actuator

#显示健康具体信息  默认不会显示详细信息
management.endpoint.health.show-details:ALWAYS

启动项目!!

3、访问http://localhost:8083/actuator

除了shutdown请求为post,其他的皆为GET请求

 可以使用以下与技术无关的端点:

应用程序是Web应用程序(Spring MVC,Spring WebFlux或Jersey)

则可以使用以下附加端点:

 Actuator 端口信息

 

启用端点

默认情况下,shutdown启用除除以外的所有端点。要配置端点的启用,请使用其

management.endpoint.<id>.enabled属性。以下示例启用shutdown端点:

management.endpoint.shutdown.enabled = true

 如果您希望端点启用是选择加入而不是选择退出,请将该

management.endpoints.enabled-by-default属性设置 为false并使用各个端点 enabled属性重新加入。

以下示例启用info端点并禁用所有其他端点:

management.endpoints.enabled-by-default = false
 management.endpoint.info.enabled = true

3、个别接口的使用:

health

http://localhost:8083/actuator/health

{
    "status": "UP",
    "details": {
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 248793526272,
                "free": 194452439040,
                "threshold": 10485760
            }
        }
    }
}

/health API 接口提供的信息是由 个或多个健康指示器提供的健康信息的组合结果

Spring Boot 自带的健康指示器

 具体看官网...........

转载来自https://www.cnblogs.com/Mrchengs/p/10596508.html

猜你喜欢

转载自www.cnblogs.com/lyh233/p/12716822.html