SpringBoot has monitoring functions that can help monitor the internal operation of programs, such as monitoring status, Bean loading, environment variables, log information, thread information, etc.

1. Maven package guide

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Copy the code

2. Close authorization

Many endpoints require authorization to allow access, which can be turned off in configuration.

management:
  security.enabled: false Some endpoint access requires authorization. Disable authorization
Copy the code

3. Endpoint introduction

  • /health
{
    "status": "UP"."diskSpace": {
        "status": "UP"."total": 250685575168."free": 155073470464."threshold": 10485760}}Copy the code
  • /env
{
    "profiles": []."server.ports": {
        "local.server.port": 10500
    },
    "servletContextInitParams": {},
    "systemProperties": {
        "java.vendor": "Oracle Corporation"."jboss.modules.system.pkgs": "com.intellij.rt"."sun.java.launcher": "SUN_STANDARD"."sun.nio.ch.bugLevel": ""."sun.management.compiler": "HotSpot 64-Bit Tiered Compilers"."spring.output.ansi.enabled": "always"."os.name": "Mac OS X". }}Copy the code
  • /mappings
{
    "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
        "bean": "endpointHandlerMapping"."method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.securi ty.Principal)"
    },
    "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
        "bean": "endpointHandlerMapping"."method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    },
    "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
        "bean": "endpointHandlerMapping"."method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    },
    "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
        "bean": "endpointHandlerMapping"."method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    },
    "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
        "bean": "endpointHandlerMapping"."method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    },
    "{[/shutdown || /shutdown.json],methods=[POST],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
        "bean": "endpointHandlerMapping"."method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.ShutdownMvcEndpoint.invoke()"
    },
    "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
        "bean": "endpointHandlerMapping"."method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"}}Copy the code
  • /shutdown

Shutting down the service requires the endpoint to be released in the configuration and requires POST request mode

endpoints:
  shutdown.enabled: true Enable the remote shutdown service
Copy the code
The 2019-11-13 23:48:07, 929 [INFO] [16] Thread - [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext:984] [] Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@517566b: startup date [Wed Nov 13 23:44:15 CST 2019]; Root of Context hierarchy 2019-11-13 23:48:07/931 [INFO] [thread-16] [org. Springframework. Context. Support. DefaultLifecycleProcessor: 358] [] Stopping beans in phase 0 2019-11-13 23:48:07, 933  [INFO] [Thread-16] [org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter:449] [] Unregistering Exposed JMX-exposed Beans on shutdown 2019-11-13 23:48:07,933 [INFO] [org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter:241] [] Unregistering JMX-exposed beans 2019-11-13 23:48:07, 934 [INFO] [16] Thread - [. Org. Springframework. JMX export. The annotation. AnnotationMBeanExporter: 449] [] Unregistering Jmx-exposed Beans on shutdown 2019-11-13 23:48:07,935 [INFO] [Thread-16] [io.undertow. Servlet :360  FrameworkServlet 'dispatcherServlet'Copy the code

Personal website

  • Gitee Pages
  • Github Pages