介绍

SpringBoot的Endpoint主要是用来监控应用服务的运行状况,并集成在Mvc中提供查看接口。内置的Endpoint比如HealthEndpoint会监控dist和db的状况,MetricsEndpoint则会监控内存和gc的状况。

Endpoint的接口如下,其中invoke()是主要的方法,用于返回监控的内容,isSensitive()用于权限控制。

public interface Endpoint<T> {String getId();boolean isEnabled();boolean isSensitive();T invoke();
}

Endpoint的加载还是依靠spring.factories实现的。spring-boot-actuator包下的META-INF/spring.factories配置了EndpointAutoConfiguration.

自定义Endpoint

以监控内存为例

定义内存实体类

public class MemoInfo {private long maxMemo;public long getMaxMemo() {return maxMemo;}public void setMaxMemo(long maxMemo) {this.maxMemo = maxMemo;}
}

编写Endpoint类

import org.springframework.boot.actuate.endpoint.Endpoint;
public class MyEndpoint implements Endpoint<MemoInfo> {public String getId() {return "myendpoint";}public MemoInfo invoke() {MemoInfo memInfo = new MemoInfo();  Runtime runtime = Runtime.getRuntime();  memInfo.setMaxMemo(runtime.maxMemory());return memInfo;}public boolean isEnabled() {return true;}public boolean isSensitive() {return false;}
}

getId()是Endpoint唯一的标识,另外也是MVC接口对外暴露的路径,以上代码对外访问路径就是:http://localhost:8080/myendpoint。

编写配置类

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class MyEndPointAutoConfig {@Beanpublic MyEndpoint myEndPoint() {  return new MyEndpoint();  }
}

SpringBoot Endpoint相关推荐

  1. SpringBoot——SpringBoot集成WebSocket实现简单的多人聊天室

    文章目录: 1.什么是WebSocket? 2.Java中的WebSocket API 2.1 WebSocket开发中的相关注解及API方法 2.2 前端技术对WebSocket的支持 3.多人聊天 ...

  2. 大牛带你深入SpringBoot:自定义Endpoint 及实现原理

    https://www.jianshu.com/p/fd93d941bf3b Endpoint SpringBoot的Endpoint主要是用来监控应用服务的运行状况,并集成在Mvc中提供查看接口.内 ...

  3. 深入SpringBoot:自定义Endpoint

    Endpoint SpringBoot的Endpoint主要是用来监控应用服务的运行状况,并集成在Mvc中提供查看接口.内置的Endpoint比如HealthEndpoint会监控dist和db的状况 ...

  4. 从源码角度分析下 micrometer 自定义 metrics endpoint 和 springboot actuator

    大家好,我是烤鸭: 今天分享下  micrometer 的源码,和springboot集成 自定义endpoint 的使用. 1.  文档信息 官方文档: http://micrometer.io/d ...

  5. Tomcat 部署多个SpringBoot 项目:ERROR org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter

    今天在公司的测试服务器上Tomcat部署多个SpringBoot项目,启动提示如下错误信息: 2022-02-15 09:43:25.177 [localhost-startStop-1] ERROR ...

  6. Springboot 源码分析 —— @Endpoint 注解生效原理解析

    文章目录 1 WebMvcEndpointManagementContextConfiguration 1.1 webEndpointServletHandlerMapping 1.2 Control ...

  7. java endpoint_大牛带你深入SpringBoot:自定义Endpoint 及实现原理

    Endpoint SpringBoot的Endpoint主要是用来监控应用服务的运行状况,并集成在Mvc中提供查看接口.内置的Endpoint比如HealthEndpoint会监控dist和db的状况 ...

  8. 八. springboot 的指标监控 (3、定制 Endpoint )

    3.定制 Endpoint 3.1.定制 Health 信息 import org.springframework.boot.actuate.health.Health; import org.spr ...

  9. springboot中端点监管 endpoint actuator

    1.pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

最新文章

  1. 这个需求很简单,明天上线没问题吧?要不要怼回去?
  2. 2.13 向量化 Logistic 回归-深度学习-Stanford吴恩达教授
  3. pyqt5 自定义控件_PyQt5学习笔记(十六)Pyinstaller打包与SQLite数据库
  4. 2.2线性表的顺序表
  5. 有的歌声音大有的歌声音小_手机听筒声音小怎么办?别急,只需一把刷子
  6. XML文档中的xmlns、xmlns:xsi和xsi:schemaLocation
  7. 网上书店系统活动设计
  8. Photosho cs6安装字体教程
  9. Excel和word的打印预览快捷键
  10. Xshell“所选的用户密钥未在远程主机上注册”解决办法
  11. 2022山东省安全员C证试题及模拟考试
  12. LCMS零件同步-字符串解析
  13. 单片机万年历阴阳历c语言,单片机阴历阳历c算法万年历.pdf
  14. 22计算机考研上岸个人经验近万字分享(11408初试360分)
  15. Windows Speech SDK5.1的安装和使用(xp/win7)
  16. web前端入门到实战:纯HTML做出几个实用网页效果
  17. 如何将cgs2000的数据匹配到天地图坐标脱密的数据上
  18. 多媒体计算机中发出声音有两种来源,多媒体计算机的声音信息处理.pdf
  19. 又出事了?网站被攻击了?高中生?
  20. [索引] 索引失效的几种情况

热门文章

  1. Ubuntu 符号连接
  2. 如何使用U盘储存4G以上的大文件,比如说镜像文件
  3. 软件测试中tc是什么岗位,豪之诺软件测试如何让TC和Bug具备专业性
  4. 为什么房地产开发商成为智慧社区普及的有力推手?
  5. 同个一个工作簿下多个工作表相同格式
  6. 简单粒子群优化算法的函数寻优
  7. 基于图片生成古诗(nlp)
  8. 数控铣削图案及编程_数控铣床编程实例.
  9. uni.downloadFile的400状态码
  10. 【更好用的单片机】Stduino学习(三十一)红外接收模块