Springboot-22指标监控(Actuator)

1、Actuator简介

  • 每一个微服务在云上部署以后,我们都需要对其进行监控、追踪、审计、控制等。
  • SpringBoot就抽取了Actuator场景,使得我们每个微服务快速引用即可获得生产级别的应用监控、审计等功能。
  • springboot1.0与springboot2.0版本存在很大区别,2.0版本支持内容更多。

2、Actuator使用

(1)引入依赖

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

(2)浏览器访问http://localhost:8080/actuator/**

  • 通过以上访问,可以知道提供了那些可以监控的指标(health,info,…);

  • 提供有jmx和web两种访问方式,在浏览器模式中,大多数监控指标为关闭状态,需要配置手动开启。

management:
  endpoints:#配置所有端点
    enabled-by-default: true #暴露所有端点信息
    web:
      exposure:
        include: '*'  #以web方式暴露
  endpoint: #配置指定端点
    health:
      show-details: always
  • 可以使用以下指标进行监控测试
    语法:
    http://localhost:8080/actuator/endpointName/detailPath
    项目路径+actuator+指标名称+具体路径
http://localhost:8080/actuator/beans //有哪些beans
http://localhost:8080/actuator/configprops //有哪些配置
http://localhost:8080/actuator/metrics  //指标:内存、数量等
//metrics  指标监控具体值
http://localhost:8080/actuator/metrics/jvm.gc.pause
http://localhost:8080/actuator/endpointName/detailPath
......

3、Actuator Endpoint

(1)最常用的Endpoint

  • Health:监控状况,健康检查
  • Metrics:运行时指标
  • Loggers:日志记录

(2)常见监控指标

id描述
beansbeans 显示应用程序中所有Spring Bean的完整列表。
caches暴露可用的缓存
conditions显示自动配置的所有条件信息,包括匹配或不匹配的原因。
configprops显示所有@ConfigurationProperties。
healthhealth 显示应用程序运行状况信息。
info显示应用程序信息
metrics显示当前应用程序的“指标”信息
mappings显示所有@RequestMapping路径列表。

(3)管理开关
可以关闭全部端点,选择需要监控的端点开启

management:
  endpoints:
    enabled-by-default: false
  endpoint:
    beans:
      enabled: true
    health:
      enabled: true

HTTP:默认只暴露health和info Endpoint
JMX:默认暴露所有Endpoint
除过health和info,剩下的Endpoint都应该进行保护访问。如果引入SpringSecurity,则会默认配置安全访问规则。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值