实时监控 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

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

相关文章
|
运维 负载均衡 安全
以太通道详解:网络连接的桥梁
【4月更文挑战第22天】
534 0
|
存储 运维 监控
什么是 SRE?一文详解 SRE 运维体系
什么是 SRE?一文详解 SRE 运维体系
3401 1
|
Java Spring
Spring AOP切点表达式(Pointcut)详解
Spring 的 AOP 中的一个核心概念是切点(Pointcut),切点表达式定义通知(Advice)执行的范围。
5092 0
|
JSON 移动开发 JavaScript
多款顶级好用的 Vue 表单设计器测评推荐,可拖拽生成表单
Vue 前端开发中,表单组件是排在前三的高频使用的组件,如何快速构建表单,节省力气,避免重复造轮子呢,选择一款适合自己的前端表单设计器就非常重要了。本文介绍 4 款顶级好用的 Vue 表单设计器,其中最后一款卡拉云,是新一代低代码开发工具,不仅能自动生成各类表单,还可以拖拽生成其他常见的前端组件,一行代码连接前后端数据,可快速接入数据库/api。它是表单设计器的超集,可直接生成属于你的后台管理工具,无敌好用。
4178 0
多款顶级好用的 Vue 表单设计器测评推荐,可拖拽生成表单
|
应用服务中间件 nginx
Nginx的启动、停止与重启
启动  启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.
13080 0
|
2月前
|
消息中间件 NoSQL Java
SpringBoot框架常见的starter你都用过哪些 ?
本节介绍常见的Spring Boot Starter,分为官方(如Web、AOP、Redis等)与第三方(如MyBatis、MyBatis Plus)两类,用于快速集成Web开发、数据库、消息队列等功能。
211 0
|
10月前
|
测试技术 网络安全
支付宝接口代签约失败排查指南
【11月更文挑战第5天】支付宝接口代签约失败排查指南:检查参数信息(必填参数、格式、业务合理性)、确认签约状态和权限(商户状态、应用权限、用户授权)、验证网络和系统环境(网络连接、系统兼容性、服务器配置)、检查异步通知设置(通知地址、处理逻辑)、查看官方文档和错误码、联系支付宝客服。
423 14
|
数据可视化 数据挖掘 定位技术
Seaborn统计图表指南
【7月更文挑战第12天】Seaborn是Python的数据可视化库,基于Matplotlib,提供美观的统计图形。要开始使用,需通过`pip install seaborn`安装。它支持多种图表,如分布图、热图、聚类图、箱线图、小提琴图、联合分布图、点图、多变量分布图、线性关系图、树地图、时间序列图、分面绘图、分类数据图、分布对比图、多变量图和气泡图等,适用于复杂数据分析和展示。Seaborn简化了创建这些高级图表的过程,使数据可视化更直观和高效。
|
存储 分布式计算 固态存储
starrocks导入性能和分区分桶介绍
starrocks导入性能和分区分桶介绍
starrocks导入性能和分区分桶介绍

热门文章

最新文章