SpringBoot配置Actuator组件,实现系统监控
作者:知了一笑 发布时间:2021-10-27 07:46:48
目录
一、Actuator简介
二、与SpringBoot2.0整合
1、核心依赖Jar包
2、Yml配置文件
三、监控接口详解
1、Info接口
2、Health接口
3、Beans接口
4、Conditions接口
5、HeapDump接口
6、Mappings接口
7、ThreadDump接口
8、ShutDown接口
四、源代码地址
一、Actuator简介
监控分类
Actuator 提供Rest接口,展示监控信息。
接口分为三大类:
应用配置类:获取应用程序中加载的应用配置、环境变量、自动化配置报告等与SpringBoot应用相关的配置类信息。
度量指标类:获取应用程序运行过程中用于监控的度量指标,比如:内存信息、线程池信息、HTTP请求统计等。
操作控制类:提供了对应用的关闭等操作类功能。
二、与SpringBoot2.0整合
1、核心依赖Jar包
<!-- 监控依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2、Yml配置文件
# 端口
server:
port: 8016
spring:
application:
# 应用名称
name: node16-boot-actuator
management:
endpoints:
web:
exposure:
# 打开所有的监控点
include: "*"
# 自定义监控路径 monitor
# 默认值:http://localhost:8016/actuator/*
# 配置后:http://localhost:8016/monitor/*
base-path: /monitor
endpoint:
health:
show-details: always
shutdown:
# 通过指定接口关闭 SpringBoot
enabled: true
# 可以自定义端口
# server:
# port: 8089
# 描述项目基础信息
info:
app:
name: node16-boot-actuator
port: 8016
version: 1.0.0
author: cicada
三、监控接口详解
1、Info接口
Yml文件中配置的项目基础信息
路径:http://localhost:8016/monitor/info
输出:
{
"app": {
"name": "node16-boot-actuator",
"port": 8016,
"version": "1.0.0",
"author": "cicada"
}
}
2、Health接口
health 主要用来检查应用的运行状态
路径:http://localhost:8016/monitor/health
输出:
{
"status": "UP",
"details": {
"diskSpace": {
"status": "UP",
"details": {
"total": 185496236032,
"free": 140944084992,
"threshold": 10485760
}
}
}
}
3、Beans接口
展示了 bean 的类型、单例多例、别名、类的全路径、依赖Jar等内容。
路径:http://localhost:8016/monitor/beans
输出:
{
"contexts": {
"node16-boot-actuator": {
"beans": {
"endpointCachingOperationInvokerAdvisor": {
"aliases": [],
"scope": "singleton",
"type": "org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor",
"resource": "class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]",
"dependencies": ["environment"]
}
}
}
}
4、Conditions接口
查看配置在什么条件下有效,或者自动配置为什么无效。
路径:http://localhost:8016/monitor/conditions
输出:
{
"contexts": {
"node16-boot-actuator": {
"positiveMatches": {
"AuditAutoConfiguration#auditListener": [{
"condition": "OnBeanCondition",
"message": "@ConditionalOnMissingBean"
}],
}
}
5、HeapDump接口
自动生成Jvm的堆转储文件HeapDump,可以使用监控工具 VisualVM 打开此文件查看内存快照。
路径:http://localhost:8016/monitor/heapdump
6、Mappings接口
描述 URI 路径和控制器的映射关系
路径:http://localhost:8016/monitor/mappings
输出:
{
"contexts": {
"node16-boot-actuator": {
"mappings": {
"dispatcherServlets": {
"dispatcherServlet": [ {
"handler": "Actuator web endpoint 'auditevents'",
"predicate": "{GET /monitor/auditevents || application/json]}",
"details": {
"handlerMethod": {
"className": "org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping.Operat
"name": "handle",
"descriptor": "(Ljavax/servlet/http/HttpServletRequest;Ljava/util/Map;)Ljava/lang/Object;"
},
"requestMappingConditions": {
"consumes": [],
"headers": [],
"methods": ["GET"],
"params": [],
"patterns": ["/monitor/auditevents"],
"produces": [{
"mediaType": "application/vnd.spring-boot.actuator.v2+json",
"negated": false
}, {
"mediaType": "application/json",
"negated": false
}]
}
}
}
}
}
}
7、ThreadDump接口
展示线程名、线程ID、是否等待锁、线程的状态、线程锁等相关信息。
路径:http://localhost:8016/monitor/threaddump
输出:
{
"threads": [{
"threadName": "DestroyJavaVM",
"threadId": 34,
"blockedTime": -1,
"blockedCount": 0,
"waitedTime": -1,
"waitedCount": 0,
"lockName": null,
"lockOwnerId": -1,
"lockOwnerName": null,
"inNative": false,
"suspended": false,
"threadState": "RUNNABLE",
"stackTrace": [],
"lockedMonitors": [],
"lockedSynchronizers": [],
"lockInfo": null
}
]
}
8、ShutDown接口
优雅关闭 Spring Boot 应用,默认只支持POST请求。
路径:http://localhost:8016/monitor/shutdown
四、源代码地址
GitHub地址:知了一笑
https://github.com/cicadasmile/spring-boot-base
码云地址:知了一笑
https://gitee.com/cicadasmile/spring-boot-base
来源:https://mp.weixin.qq.com/s/wFGN87uD9pPlny_1oYRzQQ
猜你喜欢
- 相关知识:Java中三种简单注解介绍和代码实例一、作用用 @Deprecated注解的程序元素,不鼓励程序员使用这样的元素,通常是因为它很危
- 有时,类或方法需要对类型变量加以约束。下面是一个典型的例子,我们要寻找数组中的最小元素:public class ArrayAlg { &n
- Java-JDK * (AOP)使用及实现原理分析第一章:代理的介绍介绍:我们需要掌握的程度 * (理解) 基于反射机制掌握的程度:1.
- 正文:相关术语翻译说明:Mark,标记;Sweep,清除;Compact,整理; 也有人翻译为压缩,译者认为GC时不存在压缩这回事。Copy
- 本文介绍在C#窗体编程时,如何设置不显示右上角的最小化最大化关闭按钮。可以通过this.ControlBox这个属性的值来控制。在Windo
- 注解注解为我们在代码中添加信息提供一种形式化的方法,使我们可以在源码、编译时、运行时非常方便的使用这些数据。注解是在JAVA SE5中引入的
- 首先看如下代码示例:System.out.println(0.05 + 0.01);System.out.println(0.05 - 0.
- 什么是 Spring Boot 插件?Spring Boot 插件是一种扩展机制,它提供了一种简单的方式来扩展 Spring Boot 的功
- 首先我们定义一个可以在运行时动态的找出项目的路径WebAppRootKey,这么做的原因是为了在后面配置log4j输出文件路径的时候能随心配
- 本文实例为大家分享了unity利用图片来生成字体的具体代码,供大家参考,具体内容如下开发中,可能会用到需要将图片转换成字体的需求。BMFON
- 在Unity中实现简单的伪时间同步,只是读取数据库所在电脑的当前时间using UnityEngine;using System.Colle
- 配置绑定所谓配置绑定”就是把配置文件中的值与 JavaBean 中对应的属性进行绑定。通常,我们会把一些配置信息(例如,
- 前言CountDownLatch和CyclicBarrier两个同为java并发编程的重要工具类,它们在诸多多线程并发或并行场景中得到了广泛
- 使用System.Environment获取电脑的相关属性,入门案例,具体内容如下static void Main(string[] arg
- 做为面试常考的问题之一,每次都答的模模糊糊,有必要了解一下,首先来看一下hashmap的put方法的源码public V put(K key
- 一,栈1,概念在我们软件应用 ,栈这种后进先出数据结构的应用是非常普遍的。比如你用浏 览器上网时不管什么浏览器都有 个"后退&qu
- 全局配置无效依赖 <dependency> &n
- 前段时间因为看JUC的源码,里面有大量关于unsafe的操作,所以就来看看了.写点笔记总结下(本文基于jdk1.8):unsafe可以帮我们
- 本文实例讲述了C#实现导入CSV文件到Excel工作簿的方法。分享给大家供大家参考。具体如下:你必须在项目中添加对 Microsoft.Of
- C#实现修改文件的创建、修改和访问时间方法,主要是用到了File类的SetCreationTime、SetLastWriteTime、Set