实时监控 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只展示了简单的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

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

相关文章
|
数据安全/隐私保护
BUUCTF 被劫持的神秘礼物 1
BUUCTF 被劫持的神秘礼物 1
562 0
|
JSON 移动开发 JavaScript
多款顶级好用的 Vue 表单设计器测评推荐,可拖拽生成表单
Vue 前端开发中,表单组件是排在前三的高频使用的组件,如何快速构建表单,节省力气,避免重复造轮子呢,选择一款适合自己的前端表单设计器就非常重要了。本文介绍 4 款顶级好用的 Vue 表单设计器,其中最后一款卡拉云,是新一代低代码开发工具,不仅能自动生成各类表单,还可以拖拽生成其他常见的前端组件,一行代码连接前后端数据,可快速接入数据库/api。它是表单设计器的超集,可直接生成属于你的后台管理工具,无敌好用。
4604 0
多款顶级好用的 Vue 表单设计器测评推荐,可拖拽生成表单
|
7月前
|
存储 SQL 监控
SpringBoot- 整合Logback,滚动记录+多文件
`logback-spring.xml` 是 Spring Boot 项目中的日志配置文件,用于定义日志输出格式、级别及存储路径。支持控制台与文件双输出,按时间滚动日志,并分类记录如 SQL、错误、请求参数等信息,便于问题排查与系统监控。
|
存储 Prometheus 监控
Prometheus+Grafana普罗米修斯搭建+监控MySQL
​ `Prometheus` 是 `Cloud Native Computing Foundation` 的一个监控系统项目, 集采集、监控、报警等特点于一体。 ​ `Prometheus`主要受启发于`Google`的`Brogmon`监控系统, 从`2012`年开始由前`Google`工程师在`Soundcloud`以开源软件的形式进行研发,`2017`年底发布了基于全新存储层的`2.0`版本,当前最新版本是`2.44.0`版本。
2063 0
|
JavaScript
Vue3文字滚动(TextScroll)
这是一个可定制的文字滚动组件,支持水平和垂直滚动。主要属性包括滚动文字数组 `scrollText`、是否启用单条文字滚动 `single`、滚动区域宽高 `width` 和 `height`、滚动区域和文字样式 `boardStyle` 和 `textStyle`、滚动条数 `amount`、间距 `gap`、动画间隔 `interval` 和 `step`、以及垂直滚动时间间隔 `verticalInterval`。组件内置多种样式调整功能,并提供在线预览示例。
746 0
Vue3文字滚动(TextScroll)
|
安全 Java Spring
Spring Boot 关闭 Actuator ,满足安全工具扫描
Spring Boot 关闭 Actuator ,满足安全工具扫描
3189 0
|
druid Java 数据库连接
SpringBoot + Mybatis + Druid + PageHelper 实现多数据源分页
SpringBoot + Mybatis + Druid + PageHelper 实现多数据源分页
949 0
|
编解码 人工智能 移动开发
AIGC图像分辨率太低?快来试试像素感知扩散超分模型,你想要的细节都在这里
阿里巴巴最新自研的像素感知扩散超分模型已经开源,它把扩散模型强大的生成能力和像素级控制能力相结合,能够适应从老照片修复到AIGC图像超分的各种图像增强任务和各种图像风格,并且能够控制生成强度和增强风格。这项技术的直接应用之一是AIGC图像的后处理增强和二次生成,能够带来可观的效果提升。
1713 4
|
存储 API 调度
FreeRTOS深入教程(任务创建的深入和任务调度机制分析)
FreeRTOS深入教程(任务创建的深入和任务调度机制分析)
2805 0
|
人工智能 缓存 前端开发
下一代 AI 开发工具Vercel AI SDK 快速入门
下一代 AI 开发工具Vercel AI SDK 快速入门
1813 0

热门文章

最新文章