• Springboot的监控Springboot Actuator


    1、Springboot版本2.3.9,引入Actuator的maven依赖,如下所示:

     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.3.9.RELEASE</version>
     9         <relativePath/> <!-- lookup parent from repository -->
    10     </parent>
    11     <groupId>com.bie</groupId>
    12     <artifactId>springboot</artifactId>
    13     <version>0.0.1-SNAPSHOT</version>
    14     <name>springboot</name>
    15     <description>Demo project for Spring Boot</description>
    16     <properties>
    17         <java.version>1.8</java.version>
    18     </properties>
    19     <dependencies>
    20         <dependency>
    21             <groupId>org.springframework.boot</groupId>
    22             <artifactId>spring-boot-starter-web</artifactId>
    23         </dependency>
    24 
    25         <dependency>
    26             <groupId>org.springframework.boot</groupId>
    27             <artifactId>spring-boot-starter-test</artifactId>
    28             <scope>test</scope>
    29             <exclusions>
    30                 <exclusion>
    31                     <groupId>org.junit.vintage</groupId>
    32                     <artifactId>junit-vintage-engine</artifactId>
    33                 </exclusion>
    34             </exclusions>
    35         </dependency>
    36 
    37         <dependency>
    38             <groupId>org.springframework.boot</groupId>
    39             <artifactId>spring-boot-starter-actuator</artifactId>
    40         </dependency>
    41     </dependencies>
    42 
    43     <build>
    44         <plugins>
    45             <plugin>
    46                 <groupId>org.springframework.boot</groupId>
    47                 <artifactId>spring-boot-maven-plugin</artifactId>
    48             </plugin>
    49         </plugins>
    50     </build>
    51 
    52 </project>

    访问:http://127.0.0.1:8080/actuator,可以发现如下信息:

    该信息列出了Springboot的所有endpoint端点,可以访问上面列出的地址信息。其中该端点http://127.0.0.1:8080/actuator/health的作用是进行健康检查,检查应用的资源。在application.properties中新增如下配置,可以展示health的详情,如下所示:

    1 # 将health的详情展示出来
    2 management.endpoint.health.show-details=always

    访问:http://127.0.0.1:8080/actuator/health,可以展示磁盘资源。

    健康检查的status的四种状态,第一种是UP,表示正常,第二种是Down,表示遇到了问题,不正常,第三种是Out_Of_service,资源未在使用,或者不该去使用,第四种是unkonwn,表示不知道。

    http://127.0.0.1:8080/actuator/info,该端点是描述性端点,在application.properties中可以进行配置,如下所示:

    1 # 描述性端点,建议描述应用,可以书写应用的名称、作者、邮箱等等信息
    2 info.springboot=springboot info
    3 info.author=biehl
    4 info.email=biehl@qq.com

    访问路径之后,如下所示:

    2、Springboot的常见端点,默认只有health和info是开放的,如下所示:

    具体可以参考官网:https://docs.spring.io/spring-boot/docs/2.3.9.RELEASE/reference/htmlsingle/

    参考官网,如下所示:

    如何暴漏其他端点呢,如下所示:

    1 # 激活所有的actuator端点,如果只想激活部分端点,只需要将*替换成自己的端点,如果是多个端点以逗号分隔。
    2 management.endpoints.web.exposure.include=*

    再次访问,http://127.0.0.1:8080/actuator,如下所示:

  • 相关阅读:
    activity6.0部署BPMN文件的多种方式,直接上代码
    分享一个本地缓存解决方案 Caffeine Cache
    springBoot+Docker+K8s如何远程调试
    记录一次POI导出word文件的细节问题
    Java程序性能优化部分细节
    数据库性能优化-2
    数据库性能优化-1
    一种基于“哨兵”的分布式缓存设计
    转:Spring中的@Transactional(rollbackFor = Exception.class)属性详解
    使用dozer实现对象转换
  • 原文地址:https://www.cnblogs.com/biehongli/p/14546130.html
Copyright © 2020-2023  润新知