8.SpringBoot学习(八)——Spring Boot Actuator监控

1.简介

1.1 概述

Spring Boot includes a number of additional features to help you monitor and manage your application when you push it to production. You can choose to manage and monitor your application by using HTTP endpoints or with JMX. Auditing, health, and metrics gathering can also be automatically applied to your application.

Spring Boot包含许多附加功能,可在您将应用程序投入生产时帮助您监控和管理应用程序。您可以选择使用HTTP端点或JMX管理和监控您的应用程序。审计,健康状况和指标收集也可以自动应用于您的应用程序。

1.2 特点

Actuator endpoints let you monitor and interact with your application. Spring Boot includes a number of built-in endpoints and lets you add your own. For example, the health endpoint provides basic application health information.

监控端点使您可以监控应用程序并与之交互。 Spring Boot包含许多内置端点,您可以添加自己的端点。例如,运行健康状况端点提供基本的应用程序运行状况信息。

The following technology-agnostic endpoints are available:

ID Description
auditevents Exposes audit events information for the current application. Requires an AuditEventRepository bean.
beans Displays a complete list of all the Spring beans in your application.
caches Exposes available caches.
conditions Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match.
configprops Displays a collated list of all @ConfigurationProperties.
env Exposes properties from Spring’s ConfigurableEnvironment.
flyway Shows any Flyway database migrations that have been applied. Requires one or more Flyway beans.
health Shows application health information.
httptrace Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). Requires an HttpTraceRepository bean.
info Displays arbitrary application info.
integrationgraph Shows the Spring Integration graph. Requires a dependency on spring-integration-core.
loggers Shows and modifies the configuration of loggers in the application.
liquibase Shows any Liquibase database migrations that have been applied. Requires one or more Liquibase beans.
metrics Shows ‘metrics’ information for the current application.
mappings Displays a collated list of all @RequestMapping paths.
scheduledtasks Displays the scheduled tasks in your application.
sessions Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a Servlet-based web application using Spring Session.
shutdown Lets the application be gracefully shutdown. Disabled by default.
threaddump Performs a thread dump.

If your application is a web application (Spring MVC, Spring WebFlux, or Jersey), you can use the following additional endpoints:

ID Description
heapdump Returns an hprof heap dump file.
jolokia Exposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux). Requires a dependency on jolokia-core.
logfile Returns the contents of the logfile (if logging.file.name or logging.file.path properties have been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content.
prometheus Exposes metrics in a format that can be scraped by a Prometheus server. Requires a dependency on micrometer-registry-prometheus.

2.演示环境

  1. JDK 1.8.0_201
  2. Spring Boot 2.2.0.RELEASE
  3. 构建工具(apache maven 3.6.3)
  4. 开发工具(IntelliJ IDEA )

3.演示代码

3.1 代码说明

开启 endpoint,使用 http 进行访问

3.2 代码结构

image-20200719175106586

3.3 maven 依赖

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

3.4 配置文件

info.app.version=1.0.0
info.app.name=spring-boot-actuator
info.app.test=test

# 启动所有endpoint
management.endpoints.web.exposure.include=*
# 显示详细信息
management.endpoint.health.show-details=always

# 关闭应用程序
management.endpoint.shutdown.enabled=true

3.5 java代码

HelloController.java

@RestController
public class HelloController {
   

    @GetMapping("/hello")
    public String hello() {
   
        return "hello world";
    }
}

3.6 git 地址

spring-boot/spring-boot-05-basis/spring-boot-actuator

4.效果展示

启动 SpringBootActuatorApplication.main 方法,在 spring-boot-actuator.http 访问下列地址,观察输出信息。

### GET /actuator
GET http://localhost:8080/actuator

请求响应信息如下

GET http://localhost:8080/actuator

HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json
Transfer-Encoding: chunked
Date: Sun, 19 Jul 2020 10:05:32 GMT

{
   
  "_links": {
   
    "self": {
   
      "href": "http://localhost:8080/actuator",
      "templated": false
    },
    "beans": {
   
      "href": "http://localhost:8080/actuator/beans",
      "templated": false
    },
    "caches-cache": {
   
      "href": "http://localhost:8080/actuator/caches/{cache}",
      "templated": true
    },
    "caches": {
   
      "href": "http://localhost:8080/actuator/caches",
      "templated"
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值