Spring cloudspring bootspring boot

spring boot actuator监控详细介绍(超级详细)

2019-04-08  本文已影响3人  X兄

Spring Boot包含许多其他功能,可帮助您在将应用程序推送到生产环境时监视和管理应用程序。您可以选择使用HTTP端点或JMX来管理和监视应用程序。审核,运行状况和指标收集也可以自动应用于您的应用程序。

Spring Boot Actuator就是一款可以帮助你监控系统数据的框架,其可以监控很多很多的系统数据,如:

显示应用的健康信息

显示Info应用信息

显示HTTP跟踪信息

显示当前应用程序的“Metrics”信息

显示所有的@RequestMapping的路径信息

等等等等.....总之很成熟,很强大.

使用介绍:

1.  现在pom.xml中添加依赖:

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

对于Gradle,请使用以下声明:

dependencies {

         compile("org.springframework.boot:spring-boot-starter-actuator")

}

2. 所有的监控端点endpoints介绍:

如果您的应用程序是Web应用程序(Spring MVC,Spring WebFlux或Jersey),则可以使用以下附加端点:

注意事项:

1. 在spring boot 2.0以后,actuator默认只开启了info和health端点,要想使用其他的端点,需要在application.yml中打开;

2. 而且所有的端点都以默认的路径http://localhost:8088/actuator 开始;

如我们查看info端点的信息就是访问:http://localhost:8088/actuator/info

3. Timestamps时间戳:  端点消耗的所有时间戳(作为查询参数或在请求正文中)必须格式化为ISO 8601中指定的偏移日期和时间 。 默认的时间戳是跟我们中国的时区不符合的.

4. actuator的大部分监控请求都是以get请求的.只有少数是post请求.

5. 如果想更改默认的actuator启动路径,可以在application.yml中这样:

#调整端点的前缀路径为/

  management:

      endpoints:

         web:

            base-path: /

另外要想开启所有的端点信息也是在application.yml中

management:

   endpoints:

     web:

        exposure:

           include:"*"

注意,在这里include: "*" ,这个""双引号是必须要,在application.properties是不需要""双引号的,application.properties中是这样的:management.endpoints.web.exposure.include=*

并且health端点的信息默认也是显示的不具体的,请看默认的health是显示的什么:

"UP"就是安全健康的,"DOWN"就是有问题了.

在application.yml中开启所有的Heanth监控数据:

management:

    endpoint:

         health:

            show-details:always  #显示健康具体信息  默认不会显示详细信息

我的application.yml是这样的:

现在你可以开启服务,试试这些端点的监控数据:

http://localhost:8088/metrics

http://localhost:8088/mappings

自定义info信息:

在pom.xml中添加依赖,可以访问到pom.xml的信息:

<plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-resources-plugin</artifactId>

    <version>2.6</version>

    <configuration>

        <delimiters>

            <delimiter>@</delimiter>

        </delimiters>

        <useDefaultDelimiters>false</useDefaultDelimiters>

    </configuration>

</plugin>

在application.yml中这样配置:

访问http://localhost:8088/info,运行结果为:

上一篇 下一篇

猜你喜欢

热点阅读