个人博客
SpringBoot自带监控功能Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变量、日志信息、线程信息等。
1、Maven导包
1 2 3 4
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
|
2、关闭授权
很多端点的访问需要授权才允许访问,可以在配置中关闭授权。
1 2
| management: security.enabled: false
|
3、端点介绍
1 2 3 4 5 6 7 8 9
| { "status": "UP", "diskSpace": { "status": "UP", "total": 250685575168, "free": 155073470464, "threshold": 10485760 } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| { "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", ...... } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| { "{[/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.security.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()" } }
|
关停服务,需要在配置中放开此端点,并且需要POST请求方式
1 2
| endpoints: shutdown.enabled: true
|
1 2 3 4 5 6
| 2019-11-13 23:48:07,929 [INFO] [Thread-16] [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 JMX-exposed beans on shutdown 2019-11-13 23:48:07,933 [INFO] [Thread-16] [org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter:241] [] Unregistering JMX-exposed beans 2019-11-13 23:48:07,934 [INFO] [Thread-16] [org.springframework.jmx.export.annotation.AnnotationMBeanExporter:449] [] Unregistering JMX-exposed beans on shutdown 2019-11-13 23:48:07,935 [INFO] [Thread-16] [io.undertow.servlet:360] [] Destroying Spring FrameworkServlet 'dispatcherServlet'
|