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

posted @   Arbitrary233  阅读(1155)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示