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

简介: 实时监控 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只展示了简单的UP和DOWN状态。为了获得健康检查中所有指标的详细信息,你可以通过在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

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

相关文章
IDEA第一次上传项目到gitlab
IDEA第一次上传项目到gitlab步骤
2853 1
|
数据安全/隐私保护
BUUCTF 被劫持的神秘礼物 1
BUUCTF 被劫持的神秘礼物 1
832 0
|
缓存 Linux
Centos7配置国内yum源和epel源
本篇内容记录了Centos7如何配置国内yum源和epel源。
14876 1
|
12月前
|
存储 SQL 监控
SpringBoot- 整合Logback,滚动记录+多文件
`logback-spring.xml` 是 Spring Boot 项目中的日志配置文件,用于定义日志输出格式、级别及存储路径。支持控制台与文件双输出,按时间滚动日志,并分类记录如 SQL、错误、请求参数等信息,便于问题排查与系统监控。
|
XML Java UED
使用 Spring Boot 实现重试和补偿功能:从理论到实践
【6月更文挑战第17天】在分布式系统中,服务之间的调用可能会因为网络故障、服务器负载等原因偶尔失败。为了提高系统的可靠性和稳定性,我们经常需要实现重试和补偿功能。
1330 6
|
Docker 容器
『Docker Compose』使用国内镜像极速安装Docker Compose
📣读完这篇文章里你能收获到 - 使用国内镜像极速安装Docker Compose
23577 0
『Docker Compose』使用国内镜像极速安装Docker Compose
|
缓存 关系型数据库 MySQL
【异常解决】缓存报错:Null key returned for cache operation (maybe you are using named params on classes withou
【异常解决】缓存报错:Null key returned for cache operation (maybe you are using named params on classes withou
1977 0
|
XML Java Maven
logback在springBoot项目中的使用 springboot中使用日志进行持久化保存日志信息
这篇文章详细介绍了如何在Spring Boot项目中使用logback进行日志记录,包括Maven依赖配置、logback配置文件的编写,以及实现的日志持久化和控制台输出效果。
logback在springBoot项目中的使用 springboot中使用日志进行持久化保存日志信息
|
监控 Java Linux
JVM致命错误日志(hs_err_pid.log)分析
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xmt1139057136/article/details/82880179 致命错误出现的时候,JVM 生成了 hs_err_pid.log 这样的文件,其中往往包含了虚拟机崩溃原因的重要信息。
3706 0
|
druid Java 关系型数据库
在Spring Boot中集成Druid实现多数据源有两种常用的方式:使用Spring Boot的自动配置和手动配置。
在Spring Boot中集成Druid实现多数据源有两种常用的方式:使用Spring Boot的自动配置和手动配置。
4160 5