SpringBoot指标监控功能

随时查看SpringBoot运行状态,将状态以josn格式返回

添加Actuator功能

Spring Boot Actuator可以帮助程序员监控和管理SpringBoot应用,比如健康检查、内存使用情况统计、线程使用情况统计等。

使用方法

  1. 在被监控的项目中添加Actuator起步依赖
        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>3.1.0</version>
</dependency>
  1. 编写配置文件

添加Actuator起步依赖后,会多出一些URL,通过访问这些URL可以监控运行状态

开启所有监控端点

management.endpoints.web.exposure.include=*

  1. 启动项目后通过访问localhost:8080/actuator来访问


  • 通过URL可以调用actuator的功能:
URL 查看的数据
/env 环境属性
/health 健康检查
/mappings 显示所有@RequestMapping路径
/loggers 日志
/info 定制信息
/metrics 查看内存、CPU核心等系统参数
/trace 用户请求信息

可视化工具Spring Boot Admin

Actuator使用JSON格式展示了大量指标数据,不利于我们查看,我们可以使用可视化工具Spring Boot Admin查看actuator生成指标数据。

Spring Boot Admin是一个独立的项目,我们需要创建并运行该项目。

使用方法

  1. 创建Spring Boot Admin服务端项目

    1. 创建SpringBoot项目,添加SpringMVC和Spring Boot Admin服务端起步依赖
        <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    </dependency>
    1. 修改配置文件
    # 端口号
    server.port=9090
    #日志格式
    logging.pattern.console=%d{HH:mm:ss.SSS} %clr(%-5level) --- [%-15thread] %cyan(%-50logger{50}):%msg%n
    1. 修改启动类
    @SpringBootApplication
    //开启Spring Boot Admin服务端
    @EnableAdminServer
    public class SpringBootAdminApplication { public static void main(String[] args) {
    SpringApplication.run(SpringBootAdminApplication.class, args);
    } }
  2. 连接Spring Boot Admin项目

    在被监控的项目中连接Spring Boot Admin项目,才能使用Spring Boot Admin查看指标数据。

    1. 被监控项目添加Spring Boot Admin客户端起步依赖
        <dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>3.0.2</version>
    </dependency>
    1. 修改配置文件
    #Spring boot admin访问地址
    spring.boot.admin.client.url=http://localhost:9090



点击应用墙,可以查看监控指标:

SpringBoot指标监控功能的更多相关文章

  1. SpringBoot第十二集:度量指标监控与异步调用(2020最新最易懂)

    SpringBoot第十二集:度量指标监控与异步调用(2020最新最易懂) Spring Boot Actuator是spring boot项目一个监控模块,提供了很多原生的端点,包含了对应用系统的自 ...

  2. 【03】SpringBoot2核心技术-核心功能—数据访问_单元测试_指标监控

    3.数据访问(SQL) 3.1 数据库连接池的自动配置-HikariDataSource 1.导入JDBC场景 <dependency> <groupId>org.spring ...

  3. 【spring cloud】【spring boot】网管服务-->配置文件添加endpoints.enabled = false,SpringBoot应用监控Actuator使用的安全隐患

    转载:https://xz.aliyun.com/t/2233 ==================================================================== ...

  4. SpringBoot Actuator监控【转】

    springboot actuator 监控 springboot1.5和springboot2.0 的actuator在启动日志上的差异就很大了. springboot1.5在启动时会打印很多/XX ...

  5. 面试官:聊一聊SpringBoot服务监控机制

    目录 前言 SpringBoot 监控 HTTP Endpoints 监控 内置端点 health 端点 loggers 端点 metrics 端点 自定义监控端点 自定义监控端点常用注解 来,一起写 ...

  6. 使用springboot actuator监控应用

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...

  7. springboot(十)-监控应用

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...

  8. SpringBoot服务监控

    SpringBoot服务监控分为客户端和服务端,即服务端是监控方,客户端为被监控方. 例如需要对线上的SpringBoot服务project-A进行监控,则project-A 为客户端.而监控的服务p ...

  9. UAVStack的慢SQL数据库监控功能及其实现

    UAVStack是一个全维监控与应用运维平台.UAV.Monitor具备监控功能,包含基础监控.应用/服务性能监控.日志监控.业务监控等.在应用监控中,UAV可以根据应用实例画像:其中应用实例组件可以 ...

  10. 【Springboot】用Springboot Admin监控你的微服务应用

    1 简介 目前,微服务大行其道,各大小公司争相学习模仿,把单体应用拆得七零八落.服务多了,运行的实例多了,给运维人员的压力就更大了.如果有十几个应用,单单做Health Check就已经够费时间的了. ...

随机推荐

  1. [Blockchain] Cosmos Starport 安装的三种方式

    官方二进制包方式: # 下载 starport 二进制到 /usr/local/bin $ curl https://get.starport.network/starport! | bash   # ...

  2. [FAQ] docker-compose MySQL8 ERROR: Different lower_case_table_names settings for server

    MySQL8 启动时 lower_case_table_names 的设置和初始值不一致时,会报 ERROR. 在 docker-compose 中,只需要在命令中加入命令选项即可,并配置一个新的 v ...

  3. [FAQ] Solidity 实现倒计时 (count down) ?

    思路:一种方式是使用 ethereum-alarm-clock,另一种是合约实现当前过去了多少时间,外部进行不间断调用获得. Any else? Refer:Solidity能倒计时吗 Link:ht ...

  4. 6.prometheus监控--监控redis/rabbitmq/mongodb

    1.监控redis 1.1 redis_exporter安装方式 1.1.1 二进制源码安装方式 参考nginx二进制安装方法 redis_exporter下载地址:https://github.co ...

  5. kubenetes1.26中安装kubesphere3.4版本

    一.安装前环境准备 # kubesphere官网:https://kubesphere.io/zh/docs/v3.4/introduction/what-is-kubesphere/ # 1.kub ...

  6. 使用 Docker 搭建 gitea 私有仓库

    一.准备材料 安装环境:linux 工具:docker 软件:MySql.gitea 二.安装Docker 安装Docker:https://www.cnblogs.com/jzcn/p/156937 ...

  7. netcore热插拔dll

    项目中有有些场景用到反射挺多的,用到了反射就离不开dll的加载.此demo适用于通过反射dll运行项目中加载和删除,不影响项目. ConsoleApp: 1 using AppClassLibrary ...

  8. centos中普通用户使用sudo报错:centos is not in the sudoers file. This incident will be reported.

    centos中普通用户使用sudo报错:centos is not in the sudoers file. This incident will be reported. su - chmod u+ ...

  9. windows系统桌面壁纸切换的三种csharp办法,兼容win10及旧版,还有一个现成桌面小程序

    我自己用这些代码做的小app如下: 最新版本已经改成了服务的方式,也可以选择性添加系统的右键菜单,并且我自己使用的源码库已经开源到了nuget,大家可以直接拿来做二次开发, 新版的下载地址为:http ...

  10. linux-centos7.6-gpt-uefi安装

    目录 linux-centos7.6-gpt-uefi安装 一.需要 二.环境 三.vm新建虚拟机系统环境 四.开始安装 linux-centos7.6-gpt-uefi安装 一.需要 安装的系统适用 ...