0 环境

  1. 系统:win10
  2. 编辑器:IDEA

1 概念

  1. 监控 管理自身信息(可以自定义) 的模块

2 文件配置

1 pom的配置

  1. 监控的添加
  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-actuator</artifactId>
  4. </dependency>
  1. 详细配置
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.1.8.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example</groupId>
  12. <artifactId>demo</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>demo</name>
  15. <description>Demo project for Spring Boot</description>
  16.  
  17. <properties>
  18. <java.version>1.8</java.version>
  19. </properties>
  20.  
  21. <dependencies>
  22. <dependency>
  23. <groupId>org.springframework.boot</groupId>
  24. <artifactId>spring-boot-starter-actuator</artifactId>
  25. </dependency>
  26. <dependency>
  27. <groupId>org.springframework.boot</groupId>
  28. <artifactId>spring-boot-starter-web</artifactId>
  29. </dependency>
  30.  
  31. <dependency>
  32. <groupId>org.projectlombok</groupId>
  33. <artifactId>lombok</artifactId>
  34. <optional>true</optional>
  35. </dependency>
  36. <dependency>
  37. <groupId>org.springframework.boot</groupId>
  38. <artifactId>spring-boot-starter-test</artifactId>
  39. <scope>test</scope>
  40. </dependency>
  41.  
  42. <dependency>
  43. <groupId>com.google.guava</groupId>
  44. <artifactId>guava</artifactId>
  45. <version>20.0</version>
  46. </dependency>
  47. </dependencies>
  48.  
  49. <build>
  50. <plugins>
  51. <plugin>
  52. <groupId>org.springframework.boot</groupId>
  53. <artifactId>spring-boot-maven-plugin</artifactId>
  54. </plugin>
  55. </plugins>
  56. </build>
  57.  
  58. </project>

2 启动 访问地址

  1. locahost:8080/actuator/health

3 展示更加详细 添加properties

  1. # 展示信心详情
  2. management.endpoint.health.show-details=always
  3. # 手动配置要暴露的端点(其他的端点就是封装的 不被访问)
  4. # management.endpoints.web.exposure.include=configprops,beans
  5. # 全部端点暴露
  6. # 尤其是自定义端点时 为了省事 可以先这样做
  7. # 当然也可以用上面的方式
  8. management.endpoints.web.exposure.include=*
  1. 和上面的2一样

3 自定义actuator端点

1 概述

  1. 一种是扩展健康端点 另一种自定义端点

2 扩展健康端点

  1. 继承AbstractHealthIndicator 只需要重写即可
  1. import org.springframework.boot.actuate.health.AbstractHealthIndicator;
  2. import org.springframework.boot.actuate.health.Health;
  3. import org.springframework.stereotype.Component;
  4.  
  5. // 添加组件扫面注解
  6. @Component
  7. public class UserHealIndicator extends AbstractHealthIndicator {
  8.  
  9. @Override
  10. protected void doHealthCheck(Health.Builder builder) throws Exception {
  11. builder.up().withDetail("status", true);
  12.  
  13. }
  14. }

3 自定义端点

  1. 自定义配置 配置一下端口暴露
  1. import com.google.common.collect.ImmutableMap;
  2. import com.google.common.collect.Lists;
  3. import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
  4. import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
  5. import org.springframework.stereotype.Component;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11.  
  12. import static com.google.common.collect.Maps.newHashMap;
  13.  
  14. @Component
  15. @Endpoint(id = "users")
  16. public class UserEndpoint {
  17. @ReadOperation
  18. public List<Map<String, Object>> health(){
  19. //
  20. // ImmutableMap<String,Object> map = ImmutableMap.of("userId", "1234", "userName", "小王");
  21. // map.asMultimap()
  22. // ImmutableList<ImmutableMap<String, Object>> of = ImmutableList.of(map);
  23. // System.out.println(of.asList());
  24. // Map<String, Object> map = newHashMap();
  25. // map.put("userId","1234");
  26. // map.put("userName","user");
  27. // map.put("age", "24");
  28. Map<String, Object> map = ImmutableMap.of("userId", "1234", "userName", "小王");
  29. ArrayList<Map<String, Object>> objects = Lists.newArrayList(map);
  30.  
  31. return objects;
  32. // List<Map<String, Object>> lists = new ArrayList<>();
  33. // Map<String, Object> map = new HashMap<>();
  34. // map.put("userId", "123");
  35. // map.put("userName", "like");
  36. // lists.add(map);
  37. // return lists;
  38. }
  39. }
  1. 启动运行 localhost:8080/actuator/users

4 小结

  1. 1 使用现有的 进行配置 properties的配置
  2. 2 扩展健康端点 继承AbstractHealthIndicator 重写方法
  3. 3 自定义端点 @Component @Endpoint(id = "xxx")

springboot actuator监控笔记的更多相关文章

  1. SpringBoot Actuator监控【转】

    springboot actuator 监控 springboot1.5和springboot2.0 的actuator在启动日志上的差异就很大了. springboot1.5在启动时会打印很多/XX ...

  2. 使用springboot actuator监控应用

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...

  3. springBoot actuator监控配置及使用

    准备环境: 一个springBoot工程 第一步:添加以下依赖 <dependency> <groupId>org.springframework.boot</group ...

  4. Spring Boot Actuator监控使用详解

    在企业级应用中,学习了如何进行SpringBoot应用的功能开发,以及如何写单元测试.集成测试等还是不够的.在实际的软件开发中还需要:应用程序的监控和管理.SpringBoot的Actuator模块实 ...

  5. springboot actuator 配置安全

    springboot actuator监控是什么?类似php的phpinfor()函数,不过actuator更强大,可以查看的数据.状态更多.Actuator是Spring Boot提供的对应用系统的 ...

  6. SpringBoot系列九:SpringBoot服务整合(整合邮件服务、定时调度、Actuator监控)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 服务整合 2.背景 在进行项目开发的时候经常会遇见以下的几个问题:需要进行邮件发送.定时的任务调 ...

  7. SpringBoot Actuator — 埋点和监控

    项目中看到了有埋点监控.报表.日志分析,有点兴趣想慢慢捣鼓一下 1. 数据埋点 监控机器环境的性能和业务流程或逻辑等各项数据,并根据这些数据生成对应的指标,那么我们就称为数据埋点.比如我们想知道某个接 ...

  8. SpringBoot系列: Actuator监控

    Sprng Boot 2 actuator变动加大, 网上很多资料都都已经过期. ============================配置项============================ ...

  9. 【spring cloud】【spring boot】网管服务-->配置文件添加endpoints.enabled = false,SpringBoot应用监控Actuator使用的安全隐患

    转载:https://xz.aliyun.com/t/2233 ==================================================================== ...

随机推荐

  1. java课程之团队开发冲刺阶段1.8

    一.总结昨天进度 1.实现预装sqlite数据库,将数据库放在app的assets目录下,该目录在打包的时候不会压缩,所以数据库文件可以在安装之后继续使用,然后APP安装之后检测外部存储空间是否有这个 ...

  2. Exchange 2016 CU12安装报错

    1.         报错信息: Exchange 2016 升级 CU12补丁报错,主要是在进行第10步安装管理工具时报SeSecurityPrivilega错误,详细如下: 查看安装log信息如下 ...

  3. i春秋-web- 爆破2

    题目:flag不在变量中. 打开链接: <?php include "flag.php"; $a = @$_REQUEST['hello']; eval( "var ...

  4. 无法安装R程序包

    如题,使用insatll.packages("cluster")安装包时,会出现如下错误提示. Warning: unable to access index for reposi ...

  5. win10使用笔记本自带显卡GUP安装CUDA,版本问题

    1.GPU算力问题 查询:win+r, GPU:GeForce GTX 850m,算力5.0,还可以跑得起来深度项目 2.我们需要查看NVIDIA驱动版本,才能安装合适的CUDA版本. 在C:\Pro ...

  6. [ZJCTF 2019]NiZhuanSiWei

    0x00知识点 1:data伪协议写入文件 2:php:// php://filter用于读取源码 php://input用于执行php代码 3反序列化 0x01解题 打开题目,给了我们源码 < ...

  7. h5-动画小案例-滚动展示

    1.html区域 <div> <ul> <li><img src="../img/a.jpg" alt="">& ...

  8. MySQL之完整建表语句及数据类型

    1.创建表的完整语法 create table 表名( 字段名称 数据类型[(长度) 约束条件], 字段名称 数据类型[(长度) 约束条件] ) 必须的:字段名 数据类型 表名 可选的:长度 约束条件 ...

  9. PAT Vocabulary

    数字 单词 词性 中文意 常用 音标 non-negative 非负数 non-negative number Positive 正整数 Positive integer Negative 负数 Ne ...

  10. Python中列表的copy方法

    1.在列表中存在一个名为copy的方法,就像字面意思一样copy方法是用于复制列表元素的,示例如下: names = [‘Zhangsan’,’Lisi’,’WangErgou’] names2 = ...