springboot actuator监控笔记
0 环境
- 系统:win10
- 编辑器:IDEA
1 概念
- 监控 管理自身信息(可以自定义) 的模块
2 文件配置
1 pom的配置
- 监控的添加
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
- 详细配置
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.8.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.example</groupId>
- <artifactId>demo</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>demo</name>
- <description>Demo project for Spring Boot</description>
- <properties>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>20.0</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
2 启动 访问地址
- locahost:8080/actuator/health
3 展示更加详细 添加properties
- # 展示信心详情
- management.endpoint.health.show-details=always
- # 手动配置要暴露的端点(其他的端点就是封装的 不被访问)
- # management.endpoints.web.exposure.include=configprops,beans
- # 全部端点暴露
- # 尤其是自定义端点时 为了省事 可以先这样做
- # 当然也可以用上面的方式
- management.endpoints.web.exposure.include=*
- 和上面的2一样
3 自定义actuator端点
1 概述
- 一种是扩展健康端点 另一种自定义端点
2 扩展健康端点
- 继承AbstractHealthIndicator 只需要重写即可
- import org.springframework.boot.actuate.health.AbstractHealthIndicator;
- import org.springframework.boot.actuate.health.Health;
- import org.springframework.stereotype.Component;
- // 添加组件扫面注解
- @Component
- public class UserHealIndicator extends AbstractHealthIndicator {
- @Override
- protected void doHealthCheck(Health.Builder builder) throws Exception {
- builder.up().withDetail("status", true);
- }
- }
3 自定义端点
- 自定义配置 配置一下端口暴露
- import com.google.common.collect.ImmutableMap;
- import com.google.common.collect.Lists;
- import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
- import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import static com.google.common.collect.Maps.newHashMap;
- @Component
- @Endpoint(id = "users")
- public class UserEndpoint {
- @ReadOperation
- public List<Map<String, Object>> health(){
- //
- // ImmutableMap<String,Object> map = ImmutableMap.of("userId", "1234", "userName", "小王");
- // map.asMultimap()
- // ImmutableList<ImmutableMap<String, Object>> of = ImmutableList.of(map);
- // System.out.println(of.asList());
- // Map<String, Object> map = newHashMap();
- // map.put("userId","1234");
- // map.put("userName","user");
- // map.put("age", "24");
- Map<String, Object> map = ImmutableMap.of("userId", "1234", "userName", "小王");
- ArrayList<Map<String, Object>> objects = Lists.newArrayList(map);
- return objects;
- // List<Map<String, Object>> lists = new ArrayList<>();
- // Map<String, Object> map = new HashMap<>();
- // map.put("userId", "123");
- // map.put("userName", "like");
- // lists.add(map);
- // return lists;
- }
- }
- 启动运行 localhost:8080/actuator/users
4 小结
- 1 使用现有的 进行配置 properties的配置
- 2 扩展健康端点 继承AbstractHealthIndicator类 重写方法
- 3 自定义端点 @Component @Endpoint(id = "xxx")
springboot actuator监控笔记的更多相关文章
- SpringBoot Actuator监控【转】
springboot actuator 监控 springboot1.5和springboot2.0 的actuator在启动日志上的差异就很大了. springboot1.5在启动时会打印很多/XX ...
- 使用springboot actuator监控应用
微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...
- springBoot actuator监控配置及使用
准备环境: 一个springBoot工程 第一步:添加以下依赖 <dependency> <groupId>org.springframework.boot</group ...
- Spring Boot Actuator监控使用详解
在企业级应用中,学习了如何进行SpringBoot应用的功能开发,以及如何写单元测试.集成测试等还是不够的.在实际的软件开发中还需要:应用程序的监控和管理.SpringBoot的Actuator模块实 ...
- springboot actuator 配置安全
springboot actuator监控是什么?类似php的phpinfor()函数,不过actuator更强大,可以查看的数据.状态更多.Actuator是Spring Boot提供的对应用系统的 ...
- SpringBoot系列九:SpringBoot服务整合(整合邮件服务、定时调度、Actuator监控)
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 服务整合 2.背景 在进行项目开发的时候经常会遇见以下的几个问题:需要进行邮件发送.定时的任务调 ...
- SpringBoot Actuator — 埋点和监控
项目中看到了有埋点监控.报表.日志分析,有点兴趣想慢慢捣鼓一下 1. 数据埋点 监控机器环境的性能和业务流程或逻辑等各项数据,并根据这些数据生成对应的指标,那么我们就称为数据埋点.比如我们想知道某个接 ...
- SpringBoot系列: Actuator监控
Sprng Boot 2 actuator变动加大, 网上很多资料都都已经过期. ============================配置项============================ ...
- 【spring cloud】【spring boot】网管服务-->配置文件添加endpoints.enabled = false,SpringBoot应用监控Actuator使用的安全隐患
转载:https://xz.aliyun.com/t/2233 ==================================================================== ...
随机推荐
- java课程之团队开发冲刺阶段1.8
一.总结昨天进度 1.实现预装sqlite数据库,将数据库放在app的assets目录下,该目录在打包的时候不会压缩,所以数据库文件可以在安装之后继续使用,然后APP安装之后检测外部存储空间是否有这个 ...
- Exchange 2016 CU12安装报错
1. 报错信息: Exchange 2016 升级 CU12补丁报错,主要是在进行第10步安装管理工具时报SeSecurityPrivilega错误,详细如下: 查看安装log信息如下 ...
- i春秋-web- 爆破2
题目:flag不在变量中. 打开链接: <?php include "flag.php"; $a = @$_REQUEST['hello']; eval( "var ...
- 无法安装R程序包
如题,使用insatll.packages("cluster")安装包时,会出现如下错误提示. Warning: unable to access index for reposi ...
- win10使用笔记本自带显卡GUP安装CUDA,版本问题
1.GPU算力问题 查询:win+r, GPU:GeForce GTX 850m,算力5.0,还可以跑得起来深度项目 2.我们需要查看NVIDIA驱动版本,才能安装合适的CUDA版本. 在C:\Pro ...
- [ZJCTF 2019]NiZhuanSiWei
0x00知识点 1:data伪协议写入文件 2:php:// php://filter用于读取源码 php://input用于执行php代码 3反序列化 0x01解题 打开题目,给了我们源码 < ...
- h5-动画小案例-滚动展示
1.html区域 <div> <ul> <li><img src="../img/a.jpg" alt="">& ...
- MySQL之完整建表语句及数据类型
1.创建表的完整语法 create table 表名( 字段名称 数据类型[(长度) 约束条件], 字段名称 数据类型[(长度) 约束条件] ) 必须的:字段名 数据类型 表名 可选的:长度 约束条件 ...
- PAT Vocabulary
数字 单词 词性 中文意 常用 音标 non-negative 非负数 non-negative number Positive 正整数 Positive integer Negative 负数 Ne ...
- Python中列表的copy方法
1.在列表中存在一个名为copy的方法,就像字面意思一样copy方法是用于复制列表元素的,示例如下: names = [‘Zhangsan’,’Lisi’,’WangErgou’] names2 = ...