springboot 监控 Actuator 的设置

springboot 监控 Actuator

监控中心是针对微服务期间看,服务器内存变化(对内存,线程,日志管理等),检测服务配置连接池地址是否可用(模拟访问,懒加载),统计现在有多个bean(是Spring容器中的bean),统计SpringMVC@RequestMapping(统计http接口).
使用Actuator来查看这些信息,它是没有界面的返回的是json格式的数据
AdminUi底层使用的是Actuator实现的,只不过给它加了个可视化界面
监控中心应用场景:生产环境
使用它的原因是,它是springboot的一个附加功能,可帮助你在应用程序生产环境时监控和管理应用程序.可用使用Http的各种请求来监管,审计,收集应用的运行情况,特别对于微服务管理十分有意义.
建议使用springboot2.0.5因为它里面返回的信息更加全面.

springboot 提供了对项目的监控功能。

1.首先添加依赖包

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
     <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
   <version>2.1.3.RELEASE</version>
</dependency>

2.浏览器访问

http://127.0.0.1:8080/actuator/health 访问项目监控需要加前缀 /actuator
在这里插入图片描述
在这里插入图片描述

因为actuator默认只支持端点 /health、/info 所以访问 /env 会出现404页面。

3.配置端点
在application.properties中配置端点,

暴露部分端点

management.endpoints.web.exposure.include=info,health,beans,env

暴露所有端点

management.endpoints.web.exposure.include=*

不暴露beans端点

management.endpoints.web.exposure.exclude=beans

在上述配置中,首先使用 management.endpoints.web.exposure.include 暴露所有的端点,接着使用management.endpoints.web.exposure.exclud 排除 en 端点,这样就能够暴露除 env 外的所有 ctuator端点了。

4.端点说明
在这里插入图片描述

5.端点其他配置

# Actuator 管理端口
management.server.port=8000
#暴露 有端
management.endpoints.web.exposure.include =女
#默认情况下 有端点都不启用,此时需要按需启用端点
management.endpoints.enabled-by-default=false 
#启用端点 info
management.endpoint.info.enabled=true 
#启用端点 beans
management.endpoint.beans.enabled=true 
#启用端点 configprops 
management.endpoint.configprops.enabled=true 
#启用端点 env
management.endpont.env.enabled=true
#启用端点 health
management.endpoint.health.enabled=true 
#启用端点 mappings
management.endpont.mappings.enabed=true
#启用端点 shutdown
management.endpoint.shutdown.enabled=true 
# Actuator 端点前缀
management.endpoints.web.base -path=/manage 
#将原来的 mappings 端点的请求路径修改为 urlMappings
management.endpoints.web.path-mapping.mappings=request_mappings
# Spring MVC 视图解析器配置
spring.mvc.view.prefix=/WEB-INF/jsp/ 
spring.mvc.view.suffix=.Jsp

转载自 https://www.cnblogs.com/ming-blogs/p/10697033.html

扫描二维码关注公众号,回复: 16139698 查看本文章

猜你喜欢

转载自blog.csdn.net/munangs/article/details/123639480