SpringBoot Actuator实现

第一步:引入POM依赖

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>vnacos</artifactId>
        <groupId>com.nacos</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>actuator</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>


    <dependencies>

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

        <!--actuator核心依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!--web 可以将应用作为web方式-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>

</project>

第二部:配置文件

server:
  port: 8090
  shutdown: graceful  # 设置web服务器的关闭方式 (默认是立即关闭) 需要改优雅关闭
# 暴露所有端点
management:
  endpoints:
    enabled-by-default: false    # 下面来看一下如何细粒度的开启指定的端点,需要关闭默认开启的所有端点
    web:
      base-path: /vn   # 设置访问路径
      exposure:
#        include: '*'       # 属性可以通过逗号分隔符来配置多个端点 include=beans, loggers
         include: health,shutdown   # 开启并暴露/health端点
  endpoint:
    health:
    shutdown:
      show-details: 'always'
      enabled: true         # 开启并暴露/health端点
logging:
  file:
    name: D:/logs/vn.log    #  日志存放位置
启动类:
package vn.actuator;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author vn
 * @version 1.0
 * @date 2022/3/19 19:13
 */

@SpringBootApplication
public class VnActuatorApplication {

  public static void main(String[] args) {
      SpringApplication.run(VnActuatorApplication.class,args);
  }
}
常用的端点:

 

 

 

posted @ 2022-03-19 20:26  VNone  阅读(34)  评论(0)    收藏  举报