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


猜你喜欢
- 1、设置ssh安装ssh相关软件包:sudo apt-get install openssh-client openssh-server然后
- 在介绍程序实现之前,我们先看下Android中Activities和Task的基础知识。我们都知道,一个Activity 可以启动另一个Ac
- 我就废话不多说了,大家还是直接看代码吧!public static String mapToTxt(Map<String,String
- 这篇文章主要介绍了Java线程并发访问代码分析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参
- spring Cache注解和redis区别1.不支持TTL即不能设置过期时间 expires time,SpringCache 认为这是各
- 在之前的C#版本中, 如果我们想要进行异步的Udp, 需要单开线程接收消息, C#7.1开始, 我们可以使用async/await关键字来编
- 最近在折腾一些控制相关的软件设计,想起来状态机这个东西,对解决一些控制系统状态切换还是挺有用的。状态机(有限状态自动机)网上有很多介绍。简单
- 本文实例为大家分享了C#导出Excel的具体代码,供大家参考,具体内容如下using System;using System.Collect
- 1、仿照微信空间上传图片,显示图片数量以及超过最大,上传按钮隐藏功能2、上效果图3、上代码,主要是Adapter类/** * Created
- jdk8之前 一、java.lang.Systemlong times = System.currentTimeMillis();
- 本文实例讲述了Java实现多个wav文件合成一个的方法。分享给大家供大家参考,具体如下:前面一篇介绍了java切割wav音频文件的方法,这里
- 目录IO简介1.流Stream 2.IO流的继承结构3 File文件类3.1概述3.2创建对象3.3常用方法 3.4 练
- 前言apollo配置经常使用的方式是@value,比较便捷,如果只出现在一个类中还行,但是如果多个类中并不是很方便,特别是如果出现配置值变化
- @EventListener 异步中使用condition的问题@EventListener是spring在4.2+推出的更好的使用spri
- 本篇随笔主要介绍用Java实现简单的装饰器设计模式:先来看一下装饰器设计模式的类图:从图中可以看到,我们可以装饰Component接口的任何
- 在讲策略模式之前,我先给大家举个日常生活中的例子,从首都国际机场到XXX酒店,怎么过去?1)酒店接机服务,直接开车来接。2)打车过去。3)机
- switch语句的格式如下:(它的功能是选出一段代码执行) switch(整数选择因子) { case 整数值1 : 语句; break;
- 前言面对众多卡片层叠效果,我们的产品童鞋也突发奇想,搞出了另一种卡片层叠切换展示的交互,而且产品狗们居然要求多做几种动效给他们看,好让他们选
- 我们做项目实际中经常会遇到这样的情况,创建一个common项目(Maven项目)作为公用项目,common中有很多工具类可以供其它多个项目调
- 如下所示:package com.unionx.wanxue; import java.util.Map; import java.util