Spring Boot——监控管理

本文介绍了如何在SpringBoot项目中启用和配置actuator模块,实现应用的监控和管理。通过添加依赖、配置端点暴露,可以访问如/health、/beans、/threaddump等监控接口,获取应用状态、线程信息、heapdump等关键数据,实现对SpringBoot应用的全面监控和诊断。
摘要由CSDN通过智能技术生成

一、监控管理

通过引入spring-boot-starter-actuator,可以使用Spring Boot为我们提供的准生产环境下的应用监控和管理功能。我们可以通过HTTP,JMX,SSH协议来进行操作,自动得到审计、健康及指标信息等

1、引入依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2、配置
server:
  port: 8015
spring:
  application:
    name: springboot-actuator
management:
  endpoints:
    web:
      exposure:
        include: "*" #打开所有的监控点
      base-path: /monitor #自定义监控路径默认为http://localhost:8015/actuator
  endpoint:
    health:
      show-details:  always
    shutdown:
      enabled: true #通过指定接口关闭springboot
# 描述项目基础信息
info:
  app:
    name: boot-actuator
    port: 8015
    version: 1.0.0
    author: glp

也可以单独配置单个权限:

# 开启beans 、 mappings 访问
management.endpoints.web.exposure.include=beans,mappings
3、通过http方式访问监控端点

具体内容如下:

  • /auditevents :显示应⽤暴露的审计事件(⽐如认证进⼊)
  • /beans:显示应⽤程序中所有 Spring Bean 的完整列表
  • /caches:公开可⽤的缓存 /conditions:显示在配置和⾃动配置类上评估的条件以及它们匹配或不匹配的原因
  • /configprops:显示所有 @ConfigurationPropertie 的整理列表
  • /env:获取全部环境属性
  • /flyway:提供⼀份 Flyway 数据库迁移信息
  • /health:显示应⽤程序运⾏状况信息
  • /httptrace:显示 HTTP 跟踪信息(默认情况下,最近 100 个 HTTP 请求-响 应交换)
  • /info:获取应⽤程序的定制信息,这些信息由 info 开头的属性提供
  • /integrationgraph:显示 Spring Integration 图,需要依赖于 spring-integration-
    core
  • /loggers:显示和修改应⽤程序的配置
  • /liquibase:显示已应⽤的所有 Liquibase 数据库迁移
  • /metrics/{name} :报告指定名称的应⽤程序度量值
  • /mappings:显示所有 @RequestMapping 路径的列表
  • /scheduledtasks:显示应⽤程序中的计划任务
  • /sessions:允许从 Spring Session ⽀持的会话存储中检索和删除⽤户会话,需要使⽤ Spring Session 基于Servlet 的 Web 应⽤程序
  • /shutdown:使应⽤程序正常关闭,默认禁⽤
  • /threaddump:获取线程活动的快照

(1)访问项目描述信息
http://localhost:8015/monitor/info
可以编写一个git.properties用来描述git的相关信息
在这里插入图片描述

git.branch =master
git.commit.id = 3333
git.commit.time = 2017-12-12 12:12:12

在这里插入图片描述

(2)访问线程信息
http://localhost:8015/monitor/threaddump
在这里插入图片描述

(3)HeapDump接口
自动生成Jvm的堆转储文件HeapDump,可以使用监控工具 VisualVM 打开此文件查看内存快照。
http://localhost:8015/monitor/headdump

(4)health
health 主要用来检查应用的运行状态
http://localhost:8015/monitor/health

{"status":"UP","components":
{"diskSpace":
{"status":"UP","details":
{"total":149264121856,
"free":78478319616,
"threshold":10485760,
"exists":true}},
"ping":{"status":"UP"}}}

(5)Mappings接口
描述请求映射信息
http://localhost:8015/monitor/mappings

{"contexts":{
"springboot-actuator":
{"mappings":
{"dispatcherServlets":
{"dispatcherServlet":
[{"handler":"Actuator web endpoint 'health'",
"predicate":
"{GET [/monitor/health], produces 

(6)Beans接口
展示了 bean 的类型、单例多例、别名、类的全路径、依赖Jar等内容。
http://localhost:8015/monitor/beans

(7)Conditions接口
查看配置在什么条件下有效,或者自动配置为什么无效。
http://localhost:8015/monitor/conditions

(8)ShutDown接口
优雅关闭 Spring Boot 应用,默认只支持POST请求

以 POST 的方式访问:http://localhost:8015/monitor/shutdown
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值