SpringBoot2.x系列教程86--SpringBoot中整合监控功能

JAVA 2023-07-05 17:29:38
30阅读

SpringBoot2.x系列实例教程86--SpringBoot中融合监控功能

  创作者:一一哥

一. SpringBoot监控功能

1. 监控功能介绍

  在以前的系列产品文章内容中大家学了怎样开展Spring Boot运用的功能开发设计,及其要怎么写单元测试卷、系统测试等,殊不知,在具体的开发软件中必须做的不仅如此:还包含对应用软件的监控和管理方法。

  大家也必须即时见到自身的运用现阶段的运作状况,例如给出一个实际的時间,大家期待了解这时CPU的使用率、运行内存的使用率、连接数据库是不是一切正常及其在给出时间范围内有多少顾客要求等指标值。不仅如此,大家还期待根据数据图表、操作面板来展现所述信息。

  我们可以根据HTTP,JMX,SSH协议书来开展实际操作,全自动获得财务审计、身心健康及指标值信息等。

2. 完成流程:

  • 导入spring-boot-starter-actuator;
  • 根据http方法浏览监控端点;
  • 可开展shutdown(POST 递交,此端点默认设置关掉)。

3. 监控和管理方法端点:

4. 定制端点信息

  • 打开远程应用关掉功能: management.endpoint.shutdown.enabled=true
  • 打开所需端点: management.endpoint.beans.enabled=true
  • 定制端点浏览根途径: management.endpoints.web.base-path=/manage

二. 实际完成流程

1. 建立web项目

  大家依照以前的工作经验,建立一个web程序流程,并将之更新改造成Spring Boot新项目,实际全过程略。

2. 加上依靠

  <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId></dependency>

3. 加上配备信息

  package com.yyg.boot.config;import org.springframework.boot.actuate.health.Health;import org.springframework.boot.actuate.health.HealthIndicator;import org.springframework.stereotype.Component;/** * @Author 一一哥Sun * @Date Created in 2/5/15 * @Description Description */@Componentpublic class MyHealthIndicator implements HealthIndicator { @Override public Health getHealth(boolean includeDetails) { return null; } @Override public Health health() { //自定的查验方法 Health.up().build(); //意味着身心健康,服务项目没什么问题。 //服务项目GG了 Health.down().withDetail("message", "服务项目出现异常").build(); return null; }}

4. 建立通道类

  package com.yyg.boot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;/** * @Author 一一哥Sun * @Date Created in 2/5/15 * @Description Description */@SpringBootApplicationpublic class ActuatorApplication { public static void main(String[] args){ SpringApplication.run(ActuatorApplication.class,args); }}

5.建立application.yml环境变量

  management: #security: #enabled: false endpoint: beans: enabled: true health: show-details: always enabled: true shutdown: enabled: true #打开关掉功能,默认设置关掉 endpoints: web: base-path: "/actuator" #默认设置的浏览途径 exposure: #include: ["health","info"] include: "*" #exclude: "env,beans"

6. 起动新项目开展检测

  查询新项目的身心健康情况。

  查询新项目中的beans信息。

  查询新项目的全部配备信息。

  在postman中根据post要求方法,检测关掉新项目功能。

  

  

  

the end
免责声明:本文不代表本站的观点和立场,如有侵权请联系本站删除!本站仅提供信息存储空间服务。