Home  >  Article  >  Java  >  How to configure Actuator component in SpringBoot2

How to configure Actuator component in SpringBoot2

王林
王林forward
2023-05-14 08:46:111763browse

1. Introduction to Actuator

1. Function of monitoring component

In a production environment, it is necessary to monitor the availability of services in real time or regularly. Spring Boot's actuator (health monitoring) function provides many interfaces required for monitoring, which can configure and view the application system, and perform related function statistics.

2. Monitoring Category

Actuator provides a Rest interface to display monitoring information.
The interface is divided into three major categories:
Application configuration class: Obtain configuration class information related to SpringBoot applications such as application configuration, environment variables, automated configuration reports loaded in the application.
Metric class: Obtain the metrics used for monitoring during the running of the application, such as: memory information, thread pool information, HTTP request statistics, etc.
Operation control class: Provides operation functions such as closing the application.

2. Integration with SpringBoot2.0

1. Core dependency Jar package



    org.springframework.boot
    spring-boot-starter-actuator

2. Yml configuration file

# 端口
server:
  port: 8016
spring:
  application:
    # 应用名称
    name: node16-boot-actuator
management:
  endpoints:
    web:
      exposure:
        # 打开所有的监控点
        include: "*"
      # 自定义监控路径 monitor
      # 默认值:http://localhost:8016/actuator/*
      # 配置后:http://localhost:8016/monitor/*
      base-path: /monitor
  endpoint:
    health:
      show-details: always
    shutdown:
      # 通过指定接口关闭 SpringBoot
      enabled: true
  # 可以自定义端口
  # server:
  #   port: 8089
# 描述项目基础信息
info:
  app:
    name: node16-boot-actuator
    port: 8016
    version: 1.0.0
    author: cicada

3. Detailed explanation of monitoring interface

1. Info interface

Basic project information configured in the Yml file

路径:http://localhost:8016/monitor/info
输出:
{
    "app": {
        "name": "node16-boot-actuator",
        "port": 8016,
        "version": "1.0.0",
        "author": "cicada"
    }
}

2. Health interface

health is mainly used to check the running status of the application

路径:http://localhost:8016/monitor/health
输出:
{
    "status": "UP",
    "details": {
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 185496236032,
                "free": 140944084992,
                "threshold": 10485760
            }
        }
    }
}

3. Beans interface

shows the bean type, single instance and multiple instances, alias, full path of the class, dependent Jar, etc.

路径:http://localhost:8016/monitor/beans
输出:
{
    "contexts": {
        "node16-boot-actuator": {
        "beans": {
            "endpointCachingOperationInvokerAdvisor": {
                "aliases": [],
                "scope": "singleton",
                "type": "org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor",
                "resource": "class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]",
                "dependencies": ["environment"]
            }
        }
    }
}

4. Conditions interface

Check the conditions under which the configuration is valid, or why the automatic configuration is invalid.

路径:http://localhost:8016/monitor/conditions
输出:
{
    "contexts": {
        "node16-boot-actuator": {
            "positiveMatches": {
                "AuditAutoConfiguration#auditListener": [{
                    "condition": "OnBeanCondition",
                    "message": "@ConditionalOnMissingBean"
                }],
    }
}

5. HeapDump interface

Automatically generates the Jvm heap dump file HeapDump. You can use the monitoring tool VisualVM to open this file to view the memory snapshot.

路径:http://localhost:8016/monitor/heapdump

6. Mappings interface

Describes the mapping relationship between URI paths and controllers

路径:http://localhost:8016/monitor/mappings
输出:
{
    "contexts": {
        "node16-boot-actuator": {
            "mappings": {
                "dispatcherServlets": {
                    "dispatcherServlet": [ {
                        "handler": "Actuator web endpoint 'auditevents'",
                        "predicate": "{GET /monitor/auditevents || application/json]}",
                        "details": {
                            "handlerMethod": {
                                "className": "org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping.Operat
                                "name": "handle",
                                "descriptor": "(Ljavax/servlet/http/HttpServletRequest;Ljava/util/Map;)Ljava/lang/Object;"
                            },
                            "requestMappingConditions": {
                                "consumes": [],
                                "headers": [],
                                "methods": ["GET"],
                                "params": [],
                                "patterns": ["/monitor/auditevents"],
                                "produces": [{
                                    "mediaType": "application/vnd.spring-boot.actuator.v2+json",
                                    "negated": false
                                }, {
                                    "mediaType": "application/json",
                                    "negated": false
                                }]
                            }
                        }
                    }
            }
    }
}

7. ThreadDump interface

Displays thread name, thread ID, Whether to wait for locks, thread status, thread locks and other related information.

路径:http://localhost:8016/monitor/threaddump
输出:
{
    "threads": [{
        "threadName": "DestroyJavaVM",
        "threadId": 34,
        "blockedTime": -1,
        "blockedCount": 0,
        "waitedTime": -1,
        "waitedCount": 0,
        "lockName": null,
        "lockOwnerId": -1,
        "lockOwnerName": null,
        "inNative": false,
        "suspended": false,
        "threadState": "RUNNABLE",
        "stackTrace": [],
        "lockedMonitors": [],
        "lockedSynchronizers": [],
        "lockInfo": null
    }
    ]
}

The above is the detailed content of How to configure Actuator component in SpringBoot2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete