实时监控 spring-boot-starter-actuator的整理

一、接入

1、依赖

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

2、常用actuator endpoints列表

GET /autoconfig 查看自动配置的使用情况 true 
GET /configprops 查看配置属性,包括默认配置 true 
GET /beans 查看bean及其关系列表 true 
GET /dump 打印线程栈 true 
GET /env 查看所有环境变量 true 
GET /env/{name} 查看具体变量值 true 
GET /health 查看应用健康指标 false 
GET /info 查看应用信息 false 
GET /mappings 查看所有url映射 true 
GET /metrics 查看应用基本指标 true 
GET /metrics/{name} 查看具体指标 true 
POST /shutdown 关闭应用 true 
GET /trace 查看基本追踪信息 true 

二、暴露Actuator Endpoints

默认配置:

  • 通过HTTP暴露Actuator endpoints。

    # Use "*" to expose all endpoints, or a comma-separated list to expose selected ones
    management.endpoints.web.exposure.include=health,info       # 一般此处改为 *
    management.endpoints.web.exposure.exclude=
    
  • 通过JMX暴露Actuator endpoints。

    # Use "*" to expose all endpoints, or a comma-separated list to expose selected ones
    management.endpoints.jmx.exposure.include=*
    management.endpoints.jmx.exposure.exclude=
    

三、/health endpoint

health endpoint只展示了简单的UPDOWN状态。为了获得健康检查中所有指标的详细信息,你可以通过在application.yaml中增加如下内容:

management:
  endpoint:
    health:
      show-details: always

四、/info endpoint

info endpoint展示了应用的基本信息。它通过META-INF/build-info.properties来获得编译信息,通过git.properties来获得Git信息。它同时可以展示任何其他信息,只要这个环境property中含有infokey。

你可以增加properties到application.yaml中,比如:

# INFO ENDPOINT CONFIGURATION
info:
  app:
    name: @project.name@
    description: @project.description@
    version: @project.version@
    encoding: @project.build.sourceEncoding@
    java:
      version: @java.version@

五、自定义访问地址

management.endpoints.web.base-path=/     # 默认为/actuator
management.endpoints.web.path-mapping.health:=/healthcheck     # 默认为/health
management.endpoints.web.path-mapping.info:=/infocheck     # 默认为/info

六、打开和关闭Actuator Endpoints

默认,上述所有的endpints都是打开的,除了shutdown endpoint。

你可以通过设置management.endpoint.<id>.enabled to true or false(id是endpoint的id)来决定打开还是关闭一个actuator endpoint。

举个例子,要想打开shutdown endpoint,增加以下内容在你的application.properties文件中:

management.endpoint.shutdown.enabled=true

七、使用Spring Security保证Actuator Endpoints安全

Actuator endpoints是敏感的,必须保障进入是被授权的。如果Spring Security是包含在你的应用中,那么endpoint是通过HTTP认证被保护起来的。

如果没有, 你可以增加以下以来到你的应用中去:

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

配置中增加spring security用户

# Spring Security Default user name and password
spring:
  security:
    user:
      name: actuator
      password: actuator

注意:这种用法会对全局接口请求要求登陆

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值