SpringBoot要点之使用Actuator监控

Actuator是Springboot提供的用来对应用系统进行自省和监控的功能模块,借助于Actuator开发者可以很方便地对应用系统某些监控指标进行查看、统计等。

在pom文件中加入spring-boot-starter-actuator依赖如下:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-actuator</artifactId>
  4. </dependency>
  5. Actuator提供的主要监控项。

/autoconfig用来查看自动配置的使用情况,包括:哪些被应用、哪些未被应用以及它们未被应用的原因、哪些被排除。

/configprops可以显示一个所有@ConfigurationProperties的整理列表。

/beans可以显示Spring容器中管理的所有Bean的信息。

/dump用来查看应用所启动的所有线程,每个线程的监控内容如下图所示。

/env用来查看整个应用的配置信息,使用/env/[name]可以查看具体的配置项。

/health用来查看整个应用的健康状态,包括磁盘空间使用情况、数据库和缓存等的一些健康指标。

此外,Springboot还允许用户自定义健康指标,只需要定义一个类实现HealthIndicator接口,并将其纳入到Spring容器的管理之中。


  1. @Component
  2. public class MyHealthIndicator implements HealthIndicator{
  3. @Override
  4. public Health health() {
  5. return Health.down().withDetail("error", "spring boot error").build();
  6. }
  7. }

/info可以显示配置文件中所有以info.开头或与Git相关的一些配置项的配置信息。

/mappings用来查看整个应用的URL地址映射信息。

/metrics用来查看一些监控的基本指标,也可以使用/metrics/[name]查看具体的指标。

/shutdown是一个POST请求,用来关闭应用,由于操作比较敏感,默认情况下该请求是被禁止的,若要开启需在配置文件中添加以下配置:

endpoints.shutdown.enabled: true

/trace用来监控所有请求的追踪信息,包括:请求时间、请求头、响应头、响应耗时等信息。

Actuator监控管理

打开或关闭

Actuator监控的所有项目都定义在spring-boot-actuator-x.x.x.RELEASE.jar的org.springframework.boot.actuate.endpoint包中,包含以下Endpoint。

这些Endpoint都继承自AbstractEndpoint,AbstractEndpoint中定义了两个重要的属性:enabled和sensitive。

其中,enabled用来打开或关闭该监控项,语法为:endpoints.[endpoint_name].enabled=false/true,以关闭/autoconfig监控项为例,其配置如下。

endpoints.autoconfig.enabled=false

sensitive用来配置该监控项是否属于敏感信息,访问敏感信息需要用户具有ACTUATOR角色权限,或者使用以下配置关闭安全限制。

management.security.enabled=false

端口与地址

除了使用与应用相同的端口访问监控地址外,我们还可以在配置文件中增加 management.port 配置项来自己指定监控的请求端口。

management.port=9090

还可以通过 management.address 配置项来指定可以请求监控的IP地址,比如只能通过本机监控,可以设置 management.address = 127.0.0.1 。

原文地址:https://www.cnblogs.com/doit8791/p/11470252.html

时间: 2024-08-01 09:46:08

SpringBoot要点之使用Actuator监控的相关文章

SpringBoot系列: Actuator监控

Sprng Boot 2 actuator变动加大, 网上很多资料都都已经过期. ============================配置项============================在 application.properties 配置文件, actuator 的设置项 management.endpoints(设置 actuator 全局级的属性) 和 management.endpoint(设置 具体endpoint 属性) 开头. --------------------

使用springboot actuator监控应用

微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? 在这种框架下,微服务的监控显得尤为重要.本文主要结合Spring Boot Actuator,跟大家一起分享微服务Spring Boot Actuator的常见用法,方便我们在日常中对我们的微服务进行监控治理. Actuator监控 Spring Boot使用"习惯优于配置的理念",采用包

SpringBoot31 重识Spring01-环境搭建、Actuator监控、属性配置、多环境配置

1 前言 1.1 学习阶段说明 从2016年9月开始接触IT,学习经历主要分为以下三个阶段 1.1.1 入门阶段 从最基础的前端技术HTML.JavaScript.CSS开始入门,再到后端技术Java基础.MySQL数据库基础知识.JDBC.Servclet.JSP.利用这些简单技术实现了从前端.后台.到数据库单表的CRUD操作. 1.1.2 进阶阶段 刚入行时常常听别人说起XXX框架好NB,可以干XXX.我接触了第一个框架Spring,紧接着MyBatis:再到前端框架Angular2.Vue

springboot+druid连接池及监控配置

1. 问题描述 阿里巴巴的数据库连接池Druid在效率与稳定性都很高,被很多开发团队使用,并且自带的Druid监控也很好用,本章简单介绍下springboot+druid配置连接池及监控. 2. 解决方案 2.1 pom.xml springboot 已经有druid的starter,但是好像有点问题,不知道为什么没拿到jar包,有可能是网络问题,还是使用了原生的druid gav. <dependency> <groupId>com.alibaba</groupId>

springBoot actuator监控配置及使用

准备环境: 一个springBoot工程 第一步:添加以下依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> 第二步:在properties文件中配置actuator权限配置(否则访问一些暴露的监控信息会报401,很多博客里没有这一项

Spring Boot Actuator [监控与管理]

1. 如何添加 2. actuator 的原生端点(API) 2.1 应用类配置 2.1.1 http://localhost:8080/actuator/conditions 2.1.2 http://localhost:8080/actuator/beans 2.1.3 http://localhost:8080/actuator/configprops 2.1.4 http://localhost:8080/actuator/env & http://localhost:8080/actu

Spring Boot Actuator 监控实践

Actuator是Spring Boot提供的对应用系统的自省和监控的集成功能,可以查看应用配置的详细信息,例如自动化配置信息.创建的Spring beans以及一些环境属性等. 1.创建Spring Boot工程,pom.xml的配置如下 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId>

SpringBoot动态数据源 Druid及监控配置

package com.creditcore.services.common.dataSource; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.sql.DataSource; import org.apache.ibatis.session.SqlSessionFactory; import org.mybati

SpingCloud微服务架构学习(二)之Actuator监控

我们那我们之前编写的服务提供者为例,为项目添加如下依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> 然后启动项目,访问:http://localhost:8080/actuator/health:返回结果: {"stat