SpringBoot actuator 一
本篇文章主要介绍SpringBoot项目actuator配置相关内容。方便大家更好的使用actuator,为项目的维护提供便利。如果文章中有错误或不明确的地方,请大家望指正,谢谢!
介绍
springboot actuator,可以帮助您在将应用程序推送到生产环境时监视和管理它。您可以选择使用HTTP端点或JMX来管理和监视应用程序。审核、运行状况和度量收集也可以自动应用于您的应用程序。
使用
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
配置后,就可以通过web形式访问来获取一些应用运行信息
启动日志
192.168.xx.xxx-myapp-45516-1321 [main] INFO com.wm8.logging.Application - Starting Application on XXX with PID 45516 (C:\tool\workspace\logging\target\classes started by XXX in C:\tool\workspace\logging) 192.168.xx.xxx-myapp-45516-1326 [main] INFO com.wm8.logging.Application - No active profile set, falling back to default profiles: default 192.168.xx.xxx-myapp-45516-4161 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http) 192.168.xx.xxx-myapp-45516-4185 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8080"] 192.168.xx.xxx-myapp-45516-4186 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat] 192.168.xx.xxx-myapp-45516-4186 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.37] 192.168.xx.xxx-myapp-45516-4368 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext 192.168.xx.xxx-myapp-45516-4368 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 2934 ms 192.168.xx.xxx-myapp-45516-5311 [main] INFO o.s.s.c.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor' 192.168.xx.xxx-myapp-45516-5685 [main] INFO o.s.b.a.e.web.EndpointLinksResolver - Exposing 2 endpoint(s) beneath base path '/actuator' 192.168.xx.xxx-myapp-45516-5725 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8080"] 192.168.xx.xxx-myapp-45516-5780 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path '' 192.168.xx.xxx-myapp-45516-5806 [main] INFO com.wm8.logging.Application - Started Application in 5.407 seconds (JVM running for 6.104)
通过输出日志,可以看到对外暴露了两个端口,且base-path='/actuator'
http://127.0.0.1:8080/actuator/health
{"status":"UP"}
http://127.0.0.1:8080/actuator/info
{}
Endpoints介绍
关于这个词的翻译是终端,但是总感觉有些不易理解,我更喜欢把它称为外部访问接口。
| ID | Description |
|---|---|
|
|
当前应用的审核事件日志. 需要在项目中定义AuditEventRepository的实现类,添加注解@Component |
|
|
显示应用系统中Spring beans集合. |
|
|
显示可用的缓存. |
|
|
Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match. |
|
|
Displays a collated list of all |
|
|
Exposes properties from Spring’s |
|
|
Shows any Flyway database migrations that have been applied. Requires one or more |
|
|
显示应用健康信息. |
|
|
显示http请求的信息,默认显示最后100条。需要实现 |
|
|
显示应用信息,添加github插件。加载github配置文件信息. |
|
|
Shows the Spring Integration graph. Requires a dependency on |
|
|
显示和修改应用中loggers的配置 |
|
|
Shows any Liquibase database migrations that have been applied. Requires one or more |
|
|
Shows ‘metrics’ information for the current application. |
|
|
Displays a collated list of all |
|
|
Displays the scheduled tasks in your application. |
|
|
Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a Servlet-based web application using Spring Session. |
|
|
Lets the application be gracefully shutdown. Disabled by default. |
web项目中,还可以配置如下接口
| ID | Description |
|---|---|
|
|
Returns an |
|
|
Exposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux). Requires a dependency on |
|
|
Returns the contents of the logfile (if |
|
|
Exposes metrics in a format that can be scraped by a Prometheus server. Requires a dependency on |
Endpoint可用
management: endpoint: health: enabled: true
开放Endpoint
默认支持情况:
| ID | JMX | Web |
|---|---|---|
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
Yes |
|
|
N/A |
No |
|
|
Yes |
No |
|
|
Yes |
Yes |
|
|
Yes |
No |
|
|
N/A |
No |
|
|
N/A |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
N/A |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
|
|
Yes |
No |
通过配置来开放endpoint,多个时用逗号拼接
| Property | Default |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
示例:
management: endpoints: web: exposure: include: '*' exclude: env,beans
开放所有除了evn,beans
推荐使用的配置
management: endpoint: shutdown: enabled: false health: show-details: always
浙公网安备 33010602011771号