{"id":2032,"date":"2023-04-01T20:29:53","date_gmt":"2023-04-01T12:29:53","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2032"},"modified":"2023-04-07T06:13:24","modified_gmt":"2023-04-06T22:13:24","slug":"using-spring-boot-actor-to-monitor-applications","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/01\/using-spring-boot-actor-to-monitor-applications\/","title":{"rendered":"\u4f7f\u7528 Spring Boot Actuator \u76d1\u63a7\u5e94\u7528"},"content":{"rendered":"<p>\u5fae\u670d\u52a1\u7684\u7279\u70b9\u51b3\u5b9a\u4e86\u529f\u80fd\u6a21\u5757\u7684\u90e8\u7f72\u662f\u5206\u5e03\u5f0f\u7684\uff0c\u5927\u90e8\u5206\u529f\u80fd\u6a21\u5757\u90fd\u662f\u8fd0\u884c\u5728\u4e0d\u540c\u7684\u673a\u5668\u4e0a\uff0c\u5f7c\u6b64\u901a\u8fc7\u670d\u52a1\u8c03\u7528\u8fdb\u884c\u4ea4\u4e92\uff0c\u524d\u540e\u53f0\u7684\u4e1a\u52a1\u6d41\u4f1a\u7ecf\u8fc7\u5f88\u591a\u4e2a\u5fae\u670d\u52a1\u7684\u5904\u7406\u548c\u4f20\u9012\uff0c\u51fa\u73b0\u4e86\u5f02\u5e38\u5982\u4f55\u5feb\u901f\u5b9a\u4f4d\u662f\u54ea\u4e2a\u73af\u8282\u51fa\u73b0\u4e86\u95ee\u9898\uff1f<\/p>\n<p>\u5728\u8fd9\u79cd\u6846\u67b6\u4e0b\uff0c\u5fae\u670d\u52a1\u7684\u76d1\u63a7\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\uff0c<code>Spring Boot Actuator<\/code>\u7684\u529f\u80fd\u5c31\u662f\u5bf9\u5fae\u670d\u52a1\u8fdb\u884c\u76d1\u63a7\u6cbb\u7406\u3002<\/p>\n<p><!-- more --><\/p>\n<h2>Actuator \u76d1\u63a7<\/h2>\n<p>Spring Boot \u4f7f\u7528\u201c\u4e60\u60ef\u4f18\u4e8e\u914d\u7f6e\u7684\u7406\u5ff5\u201d\uff0c\u91c7\u7528\u5305\u626b\u63cf\u548c\u81ea\u52a8\u5316\u914d\u7f6e\u7684\u673a\u5236\u6765\u52a0\u8f7d\u4f9d\u8d56 Jar \u4e2d\u7684 Spring Bean\uff0c\u4e0d\u9700\u8981\u4efb\u4f55 Xml \u914d\u7f6e\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0 Spring \u7684\u6240\u6709\u914d\u7f6e\u3002\u867d\u7136\u8fd9\u6837\u505a\u80fd\u8ba9\u6211\u4eec\u7684\u4ee3\u7801\u53d8\u5f97\u975e\u5e38\u7b80\u6d01\uff0c\u4f46\u662f\u6574\u4e2a\u5e94\u7528\u7684\u5b9e\u4f8b\u521b\u5efa\u548c\u4f9d\u8d56\u5173\u7cfb\u7b49\u4fe1\u606f\u90fd\u88ab\u79bb\u6563\u5230\u4e86\u5404\u4e2a\u914d\u7f6e\u7c7b\u7684\u6ce8\u89e3\u4e0a\uff0c\u8fd9\u4f7f\u5f97\u6211\u4eec\u5206\u6790\u6574\u4e2a\u5e94\u7528\u4e2d\u8d44\u6e90\u548c\u5b9e\u4f8b\u7684\u5404\u79cd\u5173\u7cfb\u53d8\u5f97\u975e\u5e38\u56f0\u96be\u3002<\/p>\n<p>Actuator \u662f Spring Boot \u63d0\u4f9b\u7684\u5bf9\u5e94\u7528\u7cfb\u7edf\u7684\u81ea\u7701\u548c\u76d1\u63a7\u7684\u96c6\u6210\u529f\u80fd\uff0c\u53ef\u4ee5\u67e5\u770b\u5e94\u7528\u914d\u7f6e\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4f8b\u5982\u81ea\u52a8\u5316\u914d\u7f6e\u4fe1\u606f\u3001\u521b\u5efa\u7684 Spring beans \u4ee5\u53ca\u4e00\u4e9b\u73af\u5883\u5c5e\u6027\u7b49\u3002<\/p>\n<p>\u4e3a\u4e86\u4fdd\u8bc1 Actuator \u66b4\u9732\u7684\u76d1\u63a7\u63a5\u53e3\u7684\u5b89\u5168\u6027\uff0c\u9700\u8981\u6dfb\u52a0\u5b89\u5168\u63a7\u5236\u7684\u4f9d\u8d56<code>spring-boot-start-security<\/code>\uff0c\u8bbf\u95ee\u5e94\u7528\u76d1\u63a7\u7aef\u70b9\u65f6\uff0c\u90fd\u9700\u8981\u8f93\u5165\u9a8c\u8bc1\u4fe1\u606f\u3002Security \u4f9d\u8d56\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0d\u52a0\uff0c\u4e0d\u8fdb\u884c\u5b89\u5168\u7ba1\u7406\uff0c\u4f46\u4e0d\u5efa\u8bae\u8fd9\u4e48\u505a\u3002<\/p>\n<h2>Actuator \u7684 REST \u63a5\u53e3<\/h2>\n<p>Actuator \u76d1\u63a7\u5206\u6210\u4e24\u7c7b\uff1a\u539f\u751f\u7aef\u70b9\u548c\u7528\u6237\u81ea\u5b9a\u4e49\u7aef\u70b9\uff1b\u81ea\u5b9a\u4e49\u7aef\u70b9\u4e3b\u8981\u662f\u6307\u6269\u5c55\u6027\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u5b9e\u9645\u5e94\u7528\uff0c\u5b9a\u4e49\u4e00\u4e9b\u6bd4\u8f83\u5173\u5fc3\u7684\u6307\u6807\uff0c\u5728\u8fd0\u884c\u671f\u8fdb\u884c\u76d1\u63a7\u3002<\/p>\n<p>\u539f\u751f\u7aef\u70b9\u662f\u5728\u5e94\u7528\u7a0b\u5e8f\u91cc\u63d0\u4f9b\u4f17\u591a Web \u63a5\u53e3\uff0c\u901a\u8fc7\u5b83\u4eec\u4e86\u89e3\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u5185\u90e8\u72b6\u51b5\u3002\u539f\u751f\u7aef\u70b9\u53c8\u53ef\u4ee5\u5206\u6210\u4e09\u7c7b\uff1a<\/p>\n<ul>\n<li>\u5e94\u7528\u914d\u7f6e\u7c7b\uff1a\u53ef\u4ee5\u67e5\u770b\u5e94\u7528\u5728\u8fd0\u884c\u671f\u7684\u9759\u6001\u4fe1\u606f\uff1a\u4f8b\u5982\u81ea\u52a8\u914d\u7f6e\u4fe1\u606f\u3001\u52a0\u8f7d\u7684 Spring Bean \u4fe1\u606f\u3001yml \u6587\u4ef6\u914d\u7f6e\u4fe1\u606f\u3001\u73af\u5883\u4fe1\u606f\u3001\u8bf7\u6c42\u6620\u5c04\u4fe1\u606f<\/li>\n<li>\u5ea6\u91cf\u6307\u6807\u7c7b\uff1a\u4e3b\u8981\u662f\u8fd0\u884c\u671f\u7684\u52a8\u6001\u4fe1\u606f\uff0c\u4f8b\u5982\u5806\u6808\u3001\u8bf7\u6c42\u94fe\u3001\u4e00\u4e9b\u5065\u5eb7\u6307\u6807\u3001metrics \u4fe1\u606f\u7b49<\/li>\n<li>\u64cd\u4f5c\u63a7\u5236\u7c7b\uff1a\u4e3b\u8981\u662f\u6307 shutdown\uff0c\u7528\u6237\u53ef\u4ee5\u53d1\u9001\u4e00\u4e2a\u8bf7\u6c42\u5c06\u5e94\u7528\u7684\u76d1\u63a7\u529f\u80fd\u5173\u95ed<\/li>\n<\/ul>\n<p>Actuator \u63d0\u4f9b\u4e86 13 \u4e2a\u63a5\u53e3\uff0c\u5177\u4f53\u5982\u4e0b\u8868\u6240\u793a<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">HTTP\u65b9\u6cd5<\/th>\n<th style=\"text-align: left;\">\u8def\u5f84<\/th>\n<th style=\"text-align: left;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/auditevents<\/code><\/td>\n<td style=\"text-align: left;\">\u663e\u793a\u5e94\u7528\u66b4\u9732\u7684\u5ba1\u8ba1\u4e8b\u4ef6 (\u6bd4\u5982\u8ba4\u8bc1\u8fdb\u5165\u3001\u8ba2\u5355\u5931\u8d25)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/beans<\/code><\/td>\n<td style=\"text-align: left;\">\u63cf\u8ff0\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u91cc\u5168\u90e8\u7684 Bean\uff0c\u4ee5\u53ca\u5b83\u4eec\u7684\u5173\u7cfb<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/conditions<\/code><\/td>\n<td style=\"text-align: left;\">\u5c31\u662f 1.0 \u7684<code>\/autoconfig<\/code>\uff0c\u63d0\u4f9b\u4e00\u4efd\u81ea\u52a8\u914d\u7f6e\u751f\u6548\u7684\u6761\u4ef6\u60c5\u51b5\uff0c<br \/>\u8bb0\u5f55\u54ea\u4e9b\u81ea\u52a8\u914d\u7f6e\u6761\u4ef6\u901a\u8fc7\u4e86\uff0c\u54ea\u4e9b\u6ca1\u901a\u8fc7<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/configprops<\/code><\/td>\n<td style=\"text-align: left;\">\u63cf\u8ff0\u914d\u7f6e\u5c5e\u6027(\u5305\u542b\u9ed8\u8ba4\u503c)\u5982\u4f55\u6ce8\u5165Bean<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/env<\/code><\/td>\n<td style=\"text-align: left;\">\u83b7\u53d6\u5168\u90e8\u73af\u5883\u5c5e\u6027<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/env\/{name}<\/code><\/td>\n<td style=\"text-align: left;\">\u6839\u636e\u540d\u79f0\u83b7\u53d6\u7279\u5b9a\u7684\u73af\u5883\u5c5e\u6027\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/flyway<\/code><\/td>\n<td style=\"text-align: left;\">\u63d0\u4f9b\u4e00\u4efd Flyway \u6570\u636e\u5e93\u8fc1\u79fb\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/liquidbase<\/code><\/td>\n<td style=\"text-align: left;\">\u663e\u793aLiquibase \u6570\u636e\u5e93\u8fc1\u79fb\u7684\u7ea4\u7ec6\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/health<\/code><\/td>\n<td style=\"text-align: left;\">\u62a5\u544a\u5e94\u7528\u7a0b\u5e8f\u7684\u5065\u5eb7\u6307\u6807\uff0c\u8fd9\u4e9b\u503c\u7531<code>HealthIndicator<\/code>\u7684\u5b9e\u73b0\u7c7b\u63d0\u4f9b<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/heapdump<\/code><\/td>\n<td style=\"text-align: left;\">dump \u4e00\u4efd\u5e94\u7528\u7684 JVM \u5806\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/httptrace<\/code><\/td>\n<td style=\"text-align: left;\">\u663e\u793aHTTP\u8db3\u8ff9\uff0c\u6700\u8fd1100\u4e2aHTTP request\/repsponse<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/info<\/code><\/td>\n<td style=\"text-align: left;\">\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u7684\u5b9a\u5236\u4fe1\u606f\uff0c\u8fd9\u4e9b\u4fe1\u606f\u7531info\u6253\u5934\u7684\u5c5e\u6027\u63d0\u4f9b<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/logfile<\/code><\/td>\n<td style=\"text-align: left;\">\u8fd4\u56delog file\u4e2d\u7684\u5185\u5bb9(\u5982\u679c<code>logging.file<\/code>\u6216\u8005<code>logging.path<\/code>\u88ab\u8bbe\u7f6e)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/loggers<\/code><\/td>\n<td style=\"text-align: left;\">\u663e\u793a\u548c\u4fee\u6539\u914d\u7f6e\u7684loggers<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/metrics<\/code><\/td>\n<td style=\"text-align: left;\">\u62a5\u544a\u5404\u79cd\u5e94\u7528\u7a0b\u5e8f\u5ea6\u91cf\u4fe1\u606f\uff0c\u6bd4\u5982\u5185\u5b58\u7528\u91cf\u548cHTTP\u8bf7\u6c42\u8ba1\u6570<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/metrics\/{name}<\/code><\/td>\n<td style=\"text-align: left;\">\u62a5\u544a\u6307\u5b9a\u540d\u79f0\u7684\u5e94\u7528\u7a0b\u5e8f\u5ea6\u91cf\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/scheduledtasks<\/code><\/td>\n<td style=\"text-align: left;\">\u5c55\u793a\u5e94\u7528\u4e2d\u7684\u5b9a\u65f6\u4efb\u52a1\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/sessions<\/code><\/td>\n<td style=\"text-align: left;\">\u5982\u679c\u6211\u4eec\u4f7f\u7528\u4e86<code>Spring Session<\/code>\uff0c\u5c55\u793a\u5e94\u7528\u4e2d\u7684<code>HTTP sessions<\/code>\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">POST<\/td>\n<td style=\"text-align: left;\"><code>\/shutdown<\/code><\/td>\n<td style=\"text-align: left;\">\u5173\u95ed\u5e94\u7528\u7a0b\u5e8f\uff0c\u8981\u6c42<code>endpoints.shutdown.enabled<\/code>\u8bbe\u7f6e\u4e3atrue<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/mappings<\/code><\/td>\n<td style=\"text-align: left;\">\u63cf\u8ff0\u5168\u90e8\u7684 URI\u8def\u5f84\uff0c\u4ee5\u53ca\u5b83\u4eec\u548c\u63a7\u5236\u5668(\u5305\u542bActuator\u7aef\u70b9)\u7684\u6620\u5c04\u5173\u7cfb<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">GET<\/td>\n<td style=\"text-align: left;\"><code>\/threaddump<\/code><\/td>\n<td style=\"text-align: left;\">\u83b7\u53d6\u7ebf\u7a0b\u6d3b\u52a8\u7684\u5feb\u7167<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Spring Boot Actuator: Production-ready features\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/htmlsingle\/#production-ready\">https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/htmlsingle\/#production-ready<\/a><\/p>\n<h2>\u5feb\u901f\u4e0a\u624b<\/h2>\n<h3>\u76f8\u5173\u914d\u7f6e<\/h3>\n<h4>\u9879\u76ee\u4f9d\u8d56<\/h4>\n<pre><code class=\"language-xml\">&lt;dependencies&gt;\n  &lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n  &lt;\/dependency&gt;\n  &lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-starter-actuator&lt;\/artifactId&gt;\n  &lt;\/dependency&gt;\n&lt;\/dependencies&gt;<\/code><\/pre>\n<h4>\u914d\u7f6e\u6587\u4ef6<\/h4>\n<pre><code>info.app.name=spring-boot-actuator\ninfo.app.version=1.0.0\ninfo.app.test=test\n\nmanagement.endpoints.web.exposure.include=*\nmanagement.endpoint.health.show-details=always\n#management.endpoints.web.base-path=\/monitor\n\nmanagement.endpoint.shutdown.enabled=true<\/code><\/pre>\n<ul>\n<li><code>management.endpoints.web.base-path=\/monitor<\/code> \u4ee3\u8868\u542f\u7528\u5355\u72ec\u7684url\u5730\u5740\u6765\u76d1\u63a7 Spring Boot \u5e94\u7528\uff0c\u4e3a\u4e86\u5b89\u5168\u4e00\u822c\u90fd\u542f\u7528\u72ec\u7acb\u7684\u7aef\u53e3\u6765\u8bbf\u95ee\u540e\u7aef\u7684\u76d1\u63a7\u4fe1\u606f<\/li>\n<li><code>management.endpoint.shutdown.enabled=true<\/code> \u542f\u7528\u63a5\u53e3\u5173\u95ed Spring Boot<\/li>\n<\/ul>\n<p>\u914d\u7f6e\u5b8c\u6210\u4e4b\u540e\uff0c\u542f\u52a8\u9879\u76ee\u5373\u53ef\u7ee7\u7eed\u9a8c\u8bc1\u5404\u4e2a\u76d1\u63a7\u529f\u80fd<\/p>\n<h2>\u547d\u4ee4\u8be6\u89e3<\/h2>\n<p>\u5728 Spring Boot 2.x \u4e2d\u4e3a\u4e86\u5b89\u5168\u8d77\u89c1\uff0cActuator \u53ea\u5f00\u653e\u4e86\u4e24\u4e2a\u7aef\u70b9 <code>\/actuator\/health<\/code> \u548c <code>\/actuator\/info<\/code>\u3002\u53ef\u4ee5\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u6253\u5f00\u3002<\/p>\n<p>\u53ef\u4ee5\u6253\u5f00\u6240\u6709\u7684\u76d1\u63a7\u70b9<\/p>\n<pre><code>management.endpoints.web.exposure.include=*<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u9009\u62e9\u6253\u5f00\u90e8\u5206<\/p>\n<pre><code>management.endpoints.web.exposure.exclude=beans,trace<\/code><\/pre>\n<p>Actuator \u9ed8\u8ba4\u6240\u6709\u7684\u76d1\u63a7\u70b9\u8def\u5f84\u90fd\u5728<code>\/actuator\/*<\/code>\uff0c\u5f53\u7136\u5982\u679c\u6709\u9700\u8981\u8fd9\u4e2a\u8def\u5f84\u4e5f\u652f\u6301\u5b9a\u5236\u3002<\/p>\n<pre><code>management.endpoints.web.base-path=\/manage<\/code><\/pre>\n<p>\u8bbe\u7f6e\u5b8c\u91cd\u542f\u540e\uff0c\u518d\u6b21\u8bbf\u95ee\u5730\u5740\u5c31\u4f1a\u53d8\u6210<code>\/manage\/*<\/code><\/p>\n<p>Actuator \u51e0\u4e4e\u76d1\u63a7\u4e86\u5e94\u7528\u6d89\u53ca\u7684\u65b9\u65b9\u9762\u9762\uff0c\u6211\u4eec\u91cd\u70b9\u8bb2\u8ff0\u4e00\u4e9b\u7ecf\u5e38\u5728\u9879\u76ee\u4e2d\u5e38\u7528\u7684\u547d\u4ee4\u3002<\/p>\n<h3>health<\/h3>\n<p>health \u4e3b\u8981\u7528\u6765\u68c0\u67e5\u5e94\u7528\u7684\u8fd0\u884c\u72b6\u6001\uff0c\u8fd9\u662f\u4f7f\u7528\u6700\u9ad8\u9891\u7684\u4e00\u4e2a\u76d1\u63a7\u70b9\u3002\u901a\u5e38\u4f7f\u7528\u6b64\u63a5\u53e3\u63d0\u9192\u6211\u4eec\u5e94\u7528\u5b9e\u4f8b\u7684\u8fd0\u884c\u72b6\u6001\uff0c\u4ee5\u53ca\u5e94\u7528\u4e0d\u201c\u5065\u5eb7\u201d\u7684\u539f\u56e0\uff0c\u6bd4\u5982\u6570\u636e\u5e93\u8fde\u63a5\u3001\u78c1\u76d8\u7a7a\u95f4\u4e0d\u591f\u7b49\u3002<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b health \u7684\u72b6\u6001\u662f\u5f00\u653e\u7684\uff0c\u6dfb\u52a0\u4f9d\u8d56\u540e\u542f\u52a8\u9879\u76ee\uff0c\u8bbf\u95ee\uff1a<code>http:\/\/localhost:8080\/actuator\/health<\/code>\u5373\u53ef\u770b\u5230\u5e94\u7528\u7684\u72b6\u6001\u3002<\/p>\n<pre><code class=\"language-json\">{\n  &quot;status&quot; : &quot;UP&quot;\n}<\/code><\/pre>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6700\u7ec8\u7684 Spring Boot \u5e94\u7528\u7684\u72b6\u6001\u662f\u7531<code>HealthAggregator<\/code>\u6c47\u603b\u800c\u6210\u7684\uff0c\u6c47\u603b\u7684\u7b97\u6cd5\u662f\uff1a<\/p>\n<ol>\n<li>\u8bbe\u7f6e\u72b6\u6001\u7801\u987a\u5e8f\uff1a<code>setStatusOrder(Status.DOWN, Status.OUT_OF_SERVICE, Status.UP, Status.UNKNOWN);<\/code><\/li>\n<li>\u8fc7\u6ee4\u6389\u4e0d\u80fd\u8bc6\u522b\u7684\u72b6\u6001\u7801<\/li>\n<li>\u5982\u679c\u65e0\u4efb\u4f55\u72b6\u6001\u7801\uff0c\u6574\u4e2a Spring Boot \u5e94\u7528\u7684\u72b6\u6001\u662f UNKNOWN<\/li>\n<li>\u5c06\u6240\u6709\u6536\u96c6\u5230\u7684\u72b6\u6001\u7801\u6309\u7167 1 \u4e2d\u7684\u987a\u5e8f\u6392\u5e8f<\/li>\n<li>\u8fd4\u56de\u6709\u5e8f\u72b6\u6001\u7801\u5e8f\u5217\u4e2d\u7684\u7b2c\u4e00\u4e2a\u72b6\u6001\u7801\uff0c\u4f5c\u4e3a\u6574\u4e2a Spring Boot \u5e94\u7528\u7684\u72b6\u6001<\/li>\n<\/ol>\n<p>health \u901a\u8fc7\u5408\u5e76\u51e0\u4e2a\u5065\u5eb7\u6307\u6570\u68c0\u67e5\u5e94\u7528\u7684\u5065\u5eb7\u60c5\u51b5\u3002Spring Boot Actuator \u6709\u51e0\u4e2a\u9884\u5b9a\u4e49\u7684\u5065\u5eb7\u6307\u6807\u6bd4\u5982<code>DataSourceHealthIndicator<\/code>\u3001<code>DiskSpaceHealthIndicator<\/code>\u3001<code>MongoHealthIndicator<\/code>\u3001<code>RedisHealthIndicator<\/code>\u7b49\uff0c\u5b83\u4f7f\u7528\u8fd9\u4e9b\u5065\u5eb7\u6307\u6807\u4f5c\u4e3a\u5065\u5eb7\u68c0\u67e5\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u5e94\u7528\u4e2d\u4f7f\u7528 Redis\uff0cRedisHealthindicator \u5c06\u88ab\u5f53\u4f5c\u68c0\u67e5\u7684\u4e00\u90e8\u5206\uff1b\u5982\u679c\u4f7f\u7528 MongoDB\uff0c\u90a3\u4e48MongoHealthIndicator \u5c06\u88ab\u5f53\u4f5c\u68c0\u67e5\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<p>\u53ef\u4ee5\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u5173\u95ed\u7279\u5b9a\u7684\u5065\u5eb7\u68c0\u67e5\u6307\u6807\uff0c\u6bd4\u5982\u5173\u95ed redis \u7684\u5065\u5eb7\u68c0\u67e5\uff1a<\/p>\n<pre><code>management.health.redise.enabled=false<\/code><\/pre>\n<p>\u9ed8\u8ba4\uff0c\u6240\u6709\u7684\u8fd9\u4e9b\u5065\u5eb7\u6307\u6807\u88ab\u5f53\u4f5c\u5065\u5eb7\u68c0\u67e5\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<h3>info<\/h3>\n<p>info \u5c31\u662f\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u4ee5 info \u5f00\u5934\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u6bd4\u5982\u793a\u4f8b\u9879\u76ee\u4e2d\u7684\u914d\u7f6e\u662f\uff1a<\/p>\n<pre><code>info.app.name=spring-boot-actuator\ninfo.app.version=1.0.0\ninfo.app.test=test<\/code><\/pre>\n<p>\u542f\u52a8\u793a\u4f8b\u9879\u76ee\uff0c\u8bbf\u95ee\uff1a<code>http:\/\/localhost:8080\/actuator\/info<\/code>\uff0c\u8fd4\u56de\u90e8\u5206\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-json\">{\n  &quot;app&quot;: {\n    &quot;name&quot;: &quot;spring-boot-actuator&quot;,\n    &quot;version&quot;: &quot;1.0.0&quot;,\n    &quot;test&quot;: &quot;test&quot;\n  }\n}<\/code><\/pre>\n<h3>beans<\/h3>\n<p>\u6839\u636e\u793a\u4f8b\u5c31\u53ef\u4ee5\u770b\u51fa\uff0c\u5c55\u793a bean \u7684\u522b\u540d\u3001\u7c7b\u578b\u3001\u662f\u5426\u5355\u4f8b\u3001\u7c7b\u7684\u5730\u5740\u3001\u4f9d\u8d56\u7b49\u4fe1\u606f\u3002<\/p>\n<p>\u542f\u52a8\u793a\u4f8b\u9879\u76ee\uff0c\u8bbf\u95ee\uff1a<code>http:\/\/localhost:8080\/actuator\/beans<\/code>\uff0c\u8fd4\u56de\u90e8\u5206\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-json\">[\n  {\n    &quot;context&quot;: &quot;application:8080:management&quot;,\n    &quot;parent&quot;: &quot;application:8080&quot;,\n    &quot;beans&quot;: [\n      {\n        &quot;bean&quot;: &quot;embeddedServletContainerFactory&quot;,\n        &quot;aliases&quot;: [\n\n        ],\n        &quot;scope&quot;: &quot;singleton&quot;,\n        &quot;type&quot;: &quot;org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory&quot;,\n        &quot;resource&quot;: &quot;null&quot;,\n        &quot;dependencies&quot;: [\n\n        ]\n      },\n      {\n        &quot;bean&quot;: &quot;endpointWebMvcChildContextConfiguration&quot;,\n        &quot;aliases&quot;: [\n\n        ],\n        &quot;scope&quot;: &quot;singleton&quot;,\n        &quot;type&quot;: &quot;org.springframework.boot.actuate.autoconfigure.EndpointWebMvcChildContextConfiguration$$EnhancerBySpringCGLIB$$a4a10f9d&quot;,\n        &quot;resource&quot;: &quot;null&quot;,\n        &quot;dependencies&quot;: [\n\n        ]\n      }\n  }\n]<\/code><\/pre>\n<h3>conditions<\/h3>\n<p>Spring Boot \u7684\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\u975e\u5e38\u4fbf\u5229\uff0c\u4f46\u6709\u65f6\u5019\u4e5f\u610f\u5473\u7740\u51fa\u95ee\u9898\u6bd4\u8f83\u96be\u627e\u51fa\u5177\u4f53\u7684\u539f\u56e0\u3002\u4f7f\u7528 conditions \u53ef\u4ee5\u5728\u5e94\u7528\u8fd0\u884c\u65f6\u67e5\u770b\u4ee3\u7801\u7684\u67d0\u4e2a\u914d\u7f6e\u5728\u4ec0\u4e48\u6761\u4ef6\u4e0b\u751f\u6548\uff0c\u6216\u8005\u67d0\u4e2a\u81ea\u52a8\u914d\u7f6e\u4e3a\u4ec0\u4e48\u6ca1\u6709\u751f\u6548\u3002<\/p>\n<p>\u542f\u52a8\u793a\u4f8b\u9879\u76ee\uff0c\u8bbf\u95ee\uff1a<code>http:\/\/localhost:8080\/actuator\/conditions<\/code>\uff0c\u8fd4\u56de\u90e8\u5206\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-json\">{\n  &quot;positiveMatches&quot;: {\n    &quot;DevToolsDataSourceAutoConfiguration&quot;: {\n      &quot;notMatched&quot;: [\n        {\n          &quot;condition&quot;: &quot;DevToolsDataSourceAutoConfiguration.DevToolsDataSourceCondition&quot;, \n          &quot;message&quot;: &quot;DevTools DataSource Condition did not find a single DataSource bean&quot;\n        }\n      ], \n      &quot;matched&quot;: [ ]\n    }, \n    &quot;RemoteDevToolsAutoConfiguration&quot;: {\n      &quot;notMatched&quot;: [\n        {\n          &quot;condition&quot;: &quot;OnPropertyCondition&quot;, \n          &quot;message&quot;: &quot;@ConditionalOnProperty (spring.devtools.remote.secret) did not find property &#039;secret&#039;&quot;\n        }\n      ], \n      &quot;matched&quot;: [\n        {\n          &quot;condition&quot;: &quot;OnClassCondition&quot;, \n          &quot;message&quot;: &quot;@ConditionalOnClass found required classes &#039;javax.servlet.Filter&#039;, &#039;org.springframework.http.server.ServerHttpRequest&#039;; @ConditionalOnMissingClass did not find unwanted class&quot;\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n<h3>heapdump<\/h3>\n<p>\u8fd4\u56de\u4e00\u4e2a GZip \u538b\u7f29\u7684 JVM \u5806 dump<\/p>\n<p>\u542f\u52a8\u793a\u4f8b\u9879\u76ee\uff0c\u8bbf\u95ee\uff1a<code>http:\/\/localhost:8080\/actuator\/heapdump<\/code>\uff0c\u4f1a\u81ea\u52a8\u751f\u6210\u4e00\u4e2a Jvm \u7684\u5806\u6587\u4ef6 heapdump\uff0c\u53ef\u4ee5\u4f7f\u7528 JDK \u81ea\u5e26\u7684 Jvm \u76d1\u63a7\u5de5\u5177 VisualVM \u6253\u5f00\u6b64\u6587\u4ef6\u67e5\u770b\u5185\u5b58\u5feb\u7167\u3002<\/p>\n<h3>shutdown<\/h3>\n<p>\u5f00\u542f\u63a5\u53e3\u4f18\u96c5\u5173\u95ed Spring Boot \u5e94\u7528\uff0c\u8981\u4f7f\u7528\u8fd9\u4e2a\u529f\u80fd\u9996\u5148\u9700\u8981\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u5f00\u542f\uff1a<\/p>\n<pre><code>management.endpoint.shutdown.enabled=true<\/code><\/pre>\n<p>\u914d\u7f6e\u5b8c\u6210\u4e4b\u540e\uff0c\u542f\u52a8\u793a\u4f8b\u9879\u76ee\uff0c\u4f7f\u7528 curl \u6a21\u62df post \u8bf7\u6c42\u8bbf\u95ee shutdown \u63a5\u53e3\u3002<\/p>\n<p>shutdown \u63a5\u53e3\u9ed8\u8ba4\u53ea\u652f\u6301 post \u8bf7\u6c42\uff1a<\/p>\n<pre><code>curl -X POST &quot;http:\/\/localhost:8080\/actuator\/shutdown&quot;<\/code><\/pre>\n<pre><code class=\"language-json\">{\n  &quot;message&quot;: &quot;Shutting down, bye...&quot;\n}<\/code><\/pre>\n<p>\u6b64\u65f6\u4f60\u4f1a\u53d1\u73b0\u5e94\u7528\u5df2\u7ecf\u88ab\u5173\u95ed\u3002<\/p>\n<h3>mappings<\/h3>\n<p>\u63cf\u8ff0\u5168\u90e8\u7684 URI \u8def\u5f84\uff0c\u4ee5\u53ca\u5b83\u4eec\u548c\u63a7\u5236\u5668\u7684\u6620\u5c04\u5173\u7cfb<\/p>\n<p>\u542f\u52a8\u793a\u4f8b\u9879\u76ee\uff0c\u8bbf\u95ee\uff1a<code>http:\/\/localhost:8080\/actuator\/mappings<\/code>\uff0c\u8fd4\u56de\u90e8\u5206\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-json\">{\n  &quot;\/**\/favicon.ico&quot;: {\n    &quot;bean&quot;: &quot;faviconHandlerMapping&quot;\n  },\n  &quot;{[\/hello]}&quot;: {\n    &quot;bean&quot;: &quot;requestMappingHandlerMapping&quot;,\n    &quot;method&quot;: &quot;public java.lang.String com.neo.controller.HelloController.index()&quot;\n  },\n  &quot;{[\/error]}&quot;: {\n    &quot;bean&quot;: &quot;requestMappingHandlerMapping&quot;,\n    &quot;method&quot;: &quot;public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)&quot;\n  }\n}<\/code><\/pre>\n<h3>threaddump<\/h3>\n<p><code>\/threaddump<\/code>\u63a5\u53e3\u4f1a\u751f\u6210\u5f53\u524d\u7ebf\u7a0b\u6d3b\u52a8\u7684\u5feb\u7167\uff0c\u65b9\u4fbf\u5728\u5b9a\u4f4d\u95ee\u9898\u7684\u65f6\u5019\u67e5\u770b\u7ebf\u7a0b\u7684\u60c5\u51b5\u3002\u4e3b\u8981\u5c55\u793a\u4e86\u7ebf\u7a0b\u540d\u3001\u7ebf\u7a0bID\u3001\u7ebf\u7a0b\u7684\u72b6\u6001\u3001\u662f\u5426\u7b49\u5f85\u9501\u8d44\u6e90\u7b49\u4fe1\u606f\u3002<\/p>\n<p>\u542f\u52a8\u793a\u4f8b\u9879\u76ee\uff0c\u8bbf\u95ee\uff1a<code>http:\/\/localhost:8080\/actuator\/threaddump<\/code>\uff0c\u8fd4\u56de\u90e8\u5206\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-json\">[\n  {\n    &quot;threadName&quot;: &quot;http-nio-8088-exec-6&quot;,\n    &quot;threadId&quot;: 49,\n    &quot;blockedTime&quot;: -1,\n    &quot;blockedCount&quot;: 0,\n    &quot;waitedTime&quot;: -1,\n    &quot;waitedCount&quot;: 2,\n    &quot;lockName&quot;: &quot;java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@1630a501&quot;,\n    &quot;lockOwnerId&quot;: -1,\n    &quot;lockOwnerName&quot;: null,\n    &quot;inNative&quot;: false,\n    &quot;suspended&quot;: false,\n    &quot;threadState&quot;: &quot;WAITING&quot;,\n    &quot;stackTrace&quot;: [\n      {\n        &quot;methodName&quot;: &quot;park&quot;,\n        &quot;fileName&quot;: &quot;Unsafe.java&quot;,\n        &quot;lineNumber&quot;: -2,\n        &quot;className&quot;: &quot;sun.misc.Unsafe&quot;,\n        &quot;nativeMethod&quot;: true\n      },\n      ...\n      {\n        &quot;methodName&quot;: &quot;run&quot;,\n        &quot;fileName&quot;: &quot;TaskThread.java&quot;,\n        &quot;lineNumber&quot;: 61,\n        &quot;className&quot;: &quot;org.apache.tomcat.util.threads.TaskThread$WrappingRunnable&quot;,\n        &quot;nativeMethod&quot;: false\n      }\n      ...\n    ],\n    &quot;lockInfo&quot;: {\n      &quot;className&quot;: &quot;java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject&quot;,\n      &quot;identityHashCode&quot;: 372286721\n    }\n  }\n  ...\n]<\/code><\/pre>\n<p>\u751f\u4ea7\u51fa\u73b0\u95ee\u9898\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u901a\u8fc7\u5e94\u7528\u7684\u7ebf\u7a0b\u5feb\u7167\u6765\u68c0\u6d4b\u5e94\u7528\u6b63\u5728\u6267\u884c\u7684\u4efb\u52a1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5fae\u670d\u52a1\u7684\u7279\u70b9\u51b3\u5b9a\u4e86\u529f\u80fd\u6a21\u5757\u7684\u90e8\u7f72\u662f\u5206\u5e03\u5f0f\u7684\uff0c\u5927\u90e8\u5206\u529f\u80fd\u6a21\u5757\u90fd\u662f\u8fd0\u884c\u5728\u4e0d\u540c\u7684\u673a\u5668\u4e0a\uff0c\u5f7c\u6b64\u901a\u8fc7\u670d\u52a1\u8c03\u7528\u8fdb\u884c\u4ea4\u4e92\uff0c\u524d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[],"class_list":["post-2032","post","type-post","status-publish","format-standard","hentry","category-spring-boot"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2032"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2032\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}