springboot 使用Spring Boot Actuator監(jiān)控應(yīng)用小結(jié)
微服務(wù)的特點(diǎn)決定了功能模塊的部署是分布式的,大部分功能模塊都是運(yùn)行在不同的機(jī)器上,彼此通過(guò)服務(wù)調(diào)用進(jìn)行交互,前后臺(tái)的業(yè)務(wù)流會(huì)經(jīng)過(guò)很多個(gè)微服務(wù)的處理和傳遞,出現(xiàn)了異常如何快速定位是哪個(gè)環(huán)節(jié)出現(xiàn)了問(wèn)題?
在這種框架下,微服務(wù)的監(jiān)控顯得尤為重要。本文主要結(jié)合Spring Boot Actuator,跟大家一起分享微服務(wù)Spring Boot Actuator的常見(jiàn)用法,方便我們?cè)谌粘V袑?duì)我們的微服務(wù)進(jìn)行監(jiān)控治理。
Actuator監(jiān)控
Spring Boot使用“習(xí)慣優(yōu)于配置的理念”,采用包掃描和自動(dòng)化配置的機(jī)制來(lái)加載依賴jar中的Spring bean,不需要任何Xml配置,就可以實(shí)現(xiàn)Spring的所有配置。雖然這樣做能讓我們的代碼變得非常簡(jiǎn)潔,但是整個(gè)應(yīng)用的實(shí)例創(chuàng)建和依賴關(guān)系等信息都被離散到了各個(gè)配置類的注解上,這使得我們分析整個(gè)應(yīng)用中資源和實(shí)例的各種關(guān)系變得非常的困難。
Actuator是Spring Boot提供的對(duì)應(yīng)用系統(tǒng)的自省和監(jiān)控的集成功能,可以查看應(yīng)用配置的詳細(xì)信息,例如自動(dòng)化配置信息、創(chuàng)建的Spring beans以及一些環(huán)境屬性等。
Actuator監(jiān)控只需要添加以下依賴就可以完成
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies>
為了保證actuator暴露的監(jiān)控接口的安全性,需要添加安全控制的依賴spring-boot-start-security依賴,訪問(wèn)應(yīng)用監(jiān)控端點(diǎn)時(shí),都需要輸入驗(yàn)證信息。Security依賴,可以選擇不加,不進(jìn)行安全管理,但不建議這么做。
Actuator 的 REST 接口
Actuator監(jiān)控分成兩類:原生端點(diǎn)和用戶自定義端點(diǎn);自定義端點(diǎn)主要是指擴(kuò)展性,用戶可以根據(jù)自己的實(shí)際應(yīng)用,定義一些比較關(guān)心的指標(biāo),在運(yùn)行期進(jìn)行監(jiān)控。
原生端點(diǎn)是在應(yīng)用程序里提供眾多 Web 接口,通過(guò)它們了解應(yīng)用程序運(yùn)行時(shí)的內(nèi)部狀況。原生端點(diǎn)又可以分成三類:
- 應(yīng)用配置類:可以查看應(yīng)用在運(yùn)行期的靜態(tài)信息:例如自動(dòng)配置信息、加載的springbean信息、yml文件配置信息、環(huán)境信息、請(qǐng)求映射信息;
- 度量指標(biāo)類:主要是運(yùn)行期的動(dòng)態(tài)信息,例如堆棧、請(qǐng)求連、一些健康指標(biāo)、metrics信息等;
- 操作控制類:主要是指shutdown,用戶可以發(fā)送一個(gè)請(qǐng)求將應(yīng)用的監(jiān)控功能關(guān)閉。
Actuator 提供了 13 個(gè)接口,具體如下表所示。
| HTTP 方法 | 路徑 | 描述 |
|---|---|---|
| GET | /autoconfig | 提供了一份自動(dòng)配置報(bào)告,記錄哪些自動(dòng)配置條件通過(guò)了,哪些沒(méi)通過(guò) |
| GET | /configprops | 描述配置屬性(包含默認(rèn)值)如何注入Bean |
| GET | /beans | 描述應(yīng)用程序上下文里全部的Bean,以及它們的關(guān)系 |
| GET | /dump | 獲取線程活動(dòng)的快照 |
| GET | /env | 獲取全部環(huán)境屬性 |
| GET | /env/{name} | 根據(jù)名稱獲取特定的環(huán)境屬性值 |
| GET | /health | 報(bào)告應(yīng)用程序的健康指標(biāo),這些值由HealthIndicator的實(shí)現(xiàn)類提供 |
| GET | /info | 獲取應(yīng)用程序的定制信息,這些信息由info打頭的屬性提供 |
| GET | /mappings | 描述全部的URI路徑,以及它們和控制器(包含Actuator端點(diǎn))的映射關(guān)系 |
| GET | /metrics | 報(bào)告各種應(yīng)用程序度量信息,比如內(nèi)存用量和HTTP請(qǐng)求計(jì)數(shù) |
| GET | /metrics/{name} | 報(bào)告指定名稱的應(yīng)用程序度量值 |
| POST | /shutdown | 關(guān)閉應(yīng)用程序,要求endpoints.shutdown.enabled設(shè)置為true |
| GET | /trace | 提供基本的HTTP請(qǐng)求跟蹤信息(時(shí)間戳、HTTP頭等) |
快速上手
相關(guān)配置
項(xiàng)目依賴
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies>
配置文件
server: port: 8080 management: security: enabled: false #關(guān)掉安全認(rèn)證 port: 8088 #管理端口調(diào)整成8088 context-path: /monitor #actuator的訪問(wèn)路徑 endpoints: shutdown: enabled: true info: app: name: spring-boot-actuator version: 1.0.0
- management.security.enabled=false 默認(rèn)有一部分信息需要安全驗(yàn)證之后才可以查看,如果去掉這些安全認(rèn)證,直接設(shè)置management.security.enabled=false
- management.context-path=/monitor 代表啟用單獨(dú)的url地址來(lái)監(jiān)控Spring Boot應(yīng)用,為了安全一般都啟用獨(dú)立的端口來(lái)訪問(wèn)后端的監(jiān)控信息
- endpoints.shutdown.enabled=true 啟用接口關(guān)閉Spring Boot
配置完成之后,啟動(dòng)項(xiàng)目就可以繼續(xù)驗(yàn)證各個(gè)監(jiān)控功能了。
命令詳解
autoconfig
Spring Boot的自動(dòng)配置功能非常便利,但有時(shí)候也意味著出問(wèn)題比較難找出具體的原因。使用 autoconfig 可以在應(yīng)用運(yùn)行時(shí)查看代碼了某個(gè)配置在什么條件下生效,或者某個(gè)自動(dòng)配置為什么沒(méi)有生效。
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/autoconfig 返回部分信息如下:
{
"positiveMatches": {
"DevToolsDataSourceAutoConfiguration": {
"notMatched": [
{
"condition": "DevToolsDataSourceAutoConfiguration.DevToolsDataSourceCondition",
"message": "DevTools DataSource Condition did not find a single DataSource bean"
}
],
"matched": [ ]
},
"RemoteDevToolsAutoConfiguration": {
"notMatched": [
{
"condition": "OnPropertyCondition",
"message": "@ConditionalOnProperty (spring.devtools.remote.secret) did not find property 'secret'"
}
],
"matched": [
{
"condition": "OnClassCondition",
"message": "@ConditionalOnClass found required classes 'javax.servlet.Filter', 'org.springframework.http.server.ServerHttpRequest'; @ConditionalOnMissingClass did not find unwanted class"
}
]
}
}
}
configprops
查看配置文件中設(shè)置的屬性內(nèi)容,以及一些配置屬性的默認(rèn)值。
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/configprops 返回部分信息如下:
{
...
"environmentEndpoint": {
"prefix": "endpoints.env",
"properties": {
"id": "env",
"sensitive": true,
"enabled": true
}
},
"spring.http.multipart-org.springframework.boot.autoconfigure.web.MultipartProperties": {
"prefix": "spring.http.multipart",
"properties": {
"maxRequestSize": "10MB",
"fileSizeThreshold": "0",
"location": null,
"maxFileSize": "1MB",
"enabled": true,
"resolveLazily": false
}
},
"infoEndpoint": {
"prefix": "endpoints.info",
"properties": {
"id": "info",
"sensitive": false,
"enabled": true
}
}
...
}
beans
根據(jù)示例就可以看出,展示了bean的別名、類型、是否單例、類的地址、依賴等信息。
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/beans 返回部分信息如下:
[
{
"context": "application:8080:management",
"parent": "application:8080",
"beans": [
{
"bean": "embeddedServletContainerFactory",
"aliases": [
],
"scope": "singleton",
"type": "org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory",
"resource": "null",
"dependencies": [
]
},
{
"bean": "endpointWebMvcChildContextConfiguration",
"aliases": [
],
"scope": "singleton",
"type": "org.springframework.boot.actuate.autoconfigure.EndpointWebMvcChildContextConfiguration$$EnhancerBySpringCGLIB$$a4a10f9d",
"resource": "null",
"dependencies": [
]
}
}
]
dump
/dump 接口會(huì)生成當(dāng)前線程活動(dòng)的快照。這個(gè)功能非常好,方便我們?cè)谌粘6ㄎ粏?wèn)題的時(shí)候查看線程的情況。 主要展示了線程名、線程ID、線程的狀態(tài)、是否等待鎖資源等信息。
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/dump 返回部分信息如下:
[
{
"threadName": "http-nio-8088-exec-6",
"threadId": 49,
"blockedTime": -1,
"blockedCount": 0,
"waitedTime": -1,
"waitedCount": 2,
"lockName": "java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@1630a501",
"lockOwnerId": -1,
"lockOwnerName": null,
"inNative": false,
"suspended": false,
"threadState": "WAITING",
"stackTrace": [
{
"methodName": "park",
"fileName": "Unsafe.java",
"lineNumber": -2,
"className": "sun.misc.Unsafe",
"nativeMethod": true
},
{
"methodName": "park",
"fileName": "LockSupport.java",
"lineNumber": 175,
"className": "java.util.concurrent.locks.LockSupport",
"nativeMethod": false
},
{
"methodName": "await",
"fileName": "AbstractQueuedSynchronizer.java",
"lineNumber": 2039,
"className": "java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject",
"nativeMethod": false
},
...
{
"methodName": "getTask",
"fileName": "ThreadPoolExecutor.java",
"lineNumber": 1067,
"className": "java.util.concurrent.ThreadPoolExecutor",
"nativeMethod": false
},
{
"methodName": "runWorker",
"fileName": "ThreadPoolExecutor.java",
"lineNumber": 1127,
"className": "java.util.concurrent.ThreadPoolExecutor",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "ThreadPoolExecutor.java",
"lineNumber": 617,
"className": "java.util.concurrent.ThreadPoolExecutor$Worker",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "TaskThread.java",
"lineNumber": 61,
"className": "org.apache.tomcat.util.threads.TaskThread$WrappingRunnable",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "Thread.java",
"lineNumber": 745,
"className": "java.lang.Thread",
"nativeMethod": false
}
],
"lockedMonitors": [
],
"lockedSynchronizers": [
],
"lockInfo": {
"className": "java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject",
"identityHashCode": 372286721
}
}
...
]
env
展示了系統(tǒng)環(huán)境變量的配置信息,包括使用的環(huán)境變量、JVM 屬性、命令行參數(shù)、項(xiàng)目使用的jar包等信息。和configprops不同的是,configprops關(guān)注于配置信息,env關(guān)注運(yùn)行環(huán)境信息。
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/env 返回部分信息如下:
{
"profiles": [
],
"server.ports": {
"local.management.port": 8088,
"local.server.port": 8080
},
"servletContextInitParams": {
},
"systemProperties": {
"com.sun.management.jmxremote.authenticate": "false",
"java.runtime.name": "Java(TM) SE Runtime Environment",
"spring.output.ansi.enabled": "always",
"sun.boot.library.path": "C:\\Program Files\\Java\\jdk1.8.0_101\\jre\\bin",
"java.vm.version": "25.101-b13",
"java.vm.vendor": "Oracle Corporation",
"java.vendor.url": "http://java.oracle.com/",
"java.rmi.server.randomIDs": "true",
"path.separator": ";",
"java.vm.name": "Java HotSpot(TM) 64-Bit Server VM",
"file.encoding.pkg": "sun.io",
"user.country": "CN",
"user.script": "",
"sun.java.launcher": "SUN_STANDARD",
"sun.os.patch.level": "",
"PID": "5268",
"com.sun.management.jmxremote.port": "60093",
"java.vm.specification.name": "Java Virtual Machine Spe
為了避免敏感信息暴露到 /env 里,所有名為password、secret、key(或者名字中最后一段是這些)的屬性在 /env 里都會(huì)加上“*”。舉個(gè)例子,如果有一個(gè)屬性名字是database.password,那么它在/env中的顯示效果是這樣的:
"database.password":"******"
/env/{name}用法
就是env的擴(kuò)展 可以獲取指定配置信息,比如: http://localhost:8088/monitor/env/java.vm.version ,返回: {"java.vm.version":"25.101-b13"}
health
可以看到 HealthEndPoint 給我們提供默認(rèn)的監(jiān)控結(jié)果,包含 磁盤檢測(cè)和數(shù)據(jù)庫(kù)檢測(cè)
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/health 返回部分信息,下面的JSON響應(yīng)是由狀態(tài)、磁盤空間和db。描述了應(yīng)用程序的整體健康狀態(tài),UP 表明應(yīng)用程序是健康的。磁盤空間描述總磁盤空間,剩余的磁盤空間和最小閾值。 application.properties 閾值是可配置的
{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 209715195904,
"free": 183253909504,
"threshold": 10485760
}
"db": {
"status": "UP",
"database": "MySQL",
"hello": 1
}
}
其實(shí)看 Spring Boot-actuator 源碼,你會(huì)發(fā)現(xiàn) HealthEndPoint 提供的信息不僅限于此,org.springframework.boot.actuate.health 包下 你會(huì)發(fā)現(xiàn) ElasticsearchHealthIndicator、RedisHealthIndicator、RabbitHealthIndicator 等
info
info就是我們自己配置在配置文件中以Info開(kāi)頭的配置信息,比如我們?cè)谑纠?xiàng)目中的配置是:
info: app: name: spring-boot-actuator version: 1.0.0
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/info 返回部分信息如下:
{
"app": {
"name": "spring-boot-actuator",
"version": "1.0.0"
}
}
mappings
描述全部的URI路徑,以及它們和控制器的映射關(guān)系
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/mappings 返回部分信息如下:
{
"/**/favicon.ico": {
"bean": "faviconHandlerMapping"
},
"{[/hello]}": {
"bean": "requestMappingHandlerMapping",
"method": "public java.lang.String com.neo.controller.HelloController.index()"
},
"{[/error]}": {
"bean": "requestMappingHandlerMapping",
"method": "public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)"
}
}
metrics
最重要的監(jiān)控內(nèi)容之一,主要監(jiān)控了JVM內(nèi)容使用、GC情況、類加載信息等。
啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/metrics 返回部分信息如下:
{
"mem": 337132,
"mem.free": 183380,
"processors": 4,
"instance.uptime": 254552,
"uptime": 259702,
"systemload.average": -1.0,
"heap.committed": 292864,
"heap.init": 129024,
"heap.used": 109483,
"heap": 1827840,
"nonheap.committed": 45248,
"nonheap.init": 2496,
"nonheap.used": 44269,
"nonheap": 0,
"threads.peak": 63,
"threads.daemon": 43,
"threads.totalStarted": 83,
"threads": 46,
"classes": 6357,
"classes.loaded": 6357,
"classes.unloaded": 0,
"gc.ps_scavenge.count": 8,
"gc.ps_scavenge.time": 99,
"gc.ps_marksweep.count": 1,
"gc.ps_marksweep.time": 43,
"httpsessions.max": -1,
"httpsessions.active": 0
}
對(duì) /metrics 接口提供的信息進(jìn)行簡(jiǎn)單分類如下表:
| 分類 | 前綴 | 報(bào)告內(nèi)容 |
|---|---|---|
| 垃圾收集器 | gc.* | 已經(jīng)發(fā)生過(guò)的垃圾收集次數(shù),以及垃圾收集所耗費(fèi)的時(shí)間,適用于標(biāo)記-清理垃圾收集器和并行垃圾收集器(數(shù)據(jù)源自java.lang.management. GarbageCollectorMXBean) |
| 內(nèi)存 | mem.* | 分配給應(yīng)用程序的內(nèi)存數(shù)量和空閑的內(nèi)存數(shù)量(數(shù)據(jù)源自java.lang. Runtime) |
| 堆 | heap.* | 當(dāng)前內(nèi)存用量(數(shù)據(jù)源自java.lang.management.MemoryUsage) |
| 類加載器 | classes.* | JVM類加載器加載與卸載的類的數(shù)量(數(shù)據(jù)源自java.lang. management.ClassLoadingMXBean) |
| 系統(tǒng) | processors、instance.uptime、uptime、systemload.average | 系統(tǒng)信息,例如處理器數(shù)量(數(shù)據(jù)源自java.lang.Runtime)、運(yùn)行時(shí)間(數(shù)據(jù)源自java.lang.management.RuntimeMXBean)、平均負(fù)載(數(shù)據(jù)源自java.lang.management.OperatingSystemMXBean) |
| 線程池 | thread.* | 線程、守護(hù)線程的數(shù)量,以及JVM啟動(dòng)后的線程數(shù)量峰值(數(shù)據(jù)源自 java.lang .management.ThreadMXBean) |
| 數(shù)據(jù)源 | datasource.* | 數(shù)據(jù)源連接的數(shù)量(源自數(shù)據(jù)源的元數(shù)據(jù),僅當(dāng)Spring應(yīng)用程序上下文里存在 DataSource Bean 的時(shí)候才會(huì)有這個(gè)信息) |
| Tomcat 會(huì)話 | httpsessions.* | Tomcat的活躍會(huì)話數(shù)和最大會(huì)話數(shù)(數(shù)據(jù)源自嵌入式Tomcat的Bean,僅在使用嵌入式Tomcat服務(wù)器運(yùn)行應(yīng)用程序時(shí)才有這個(gè)信息) |
| HTTP | counter.status. 、gauge.response. | 多種應(yīng)用程序服務(wù)HTTP請(qǐng)求的度量值與計(jì)數(shù)器 |
解釋說(shuō)明:
- 請(qǐng)注意,這里的一些度量值,比如數(shù)據(jù)源和Tomcat會(huì)話,僅在應(yīng)用程序中運(yùn)行特定組件時(shí)才有數(shù)據(jù)。你還可以注冊(cè)自己的度量信息。
- HTTP的計(jì)數(shù)器和度量值需要做一點(diǎn)說(shuō)明。counter.status 后的值是HTTP狀態(tài)碼,隨后是所請(qǐng)求的路徑。舉個(gè)例子,counter.status.200.metrics 表明/metrics端點(diǎn)返回 200(OK) 狀態(tài)碼的次數(shù)。
- HTTP的度量信息在結(jié)構(gòu)上也差不多,卻在報(bào)告另一類信息。它們?nèi)恳詆auge.response 開(kāi)頭,,表明這是HTTP響應(yīng)的度量信息。前綴后是對(duì)應(yīng)的路徑。度量值是以毫秒為單位的時(shí)間,反映了最近處理該路徑請(qǐng)求的耗時(shí)。
- 這里還有幾個(gè)特殊的值需要注意。root路徑指向的是根路徑或/。star-star代表了那些Spring 認(rèn)為是靜態(tài)資源的路徑,包括圖片、JavaScript和樣式表,其中還包含了那些找不到的資源。這就是為什么你經(jīng)常會(huì)看到 counter.status.404.star-star,這是返回了HTTP 404 (NOT FOUND) 狀態(tài)的請(qǐng)求數(shù)。
- /metrics 接口會(huì)返回所有的可用度量值,但你也可能只對(duì)某個(gè)值感興趣。要獲取單個(gè)值,請(qǐng)求時(shí)可以在URL后加上對(duì)應(yīng)的鍵名。例如,要查看空閑內(nèi)存大小,可以向 /metrics/mem.free 發(fā)一 個(gè)GET請(qǐng)求。例如訪問(wèn): http://localhost:8088/monitor/metrics/mem.free ,返回: {"mem.free":178123} 。
shutdown
開(kāi)啟接口優(yōu)雅關(guān)閉Spring Boot應(yīng)用,要使用這個(gè)功能首先需要在配置文件中開(kāi)啟:
endpoints: shutdown: enabled: true
配置完成之后,啟動(dòng)示例項(xiàng)目,訪問(wèn): http://localhost:8088/monitor/shutdown 返回部分信息如下:
{
"message": "Shutting down, bye..."
}
此時(shí)你會(huì)發(fā)現(xiàn)應(yīng)用已經(jīng)被關(guān)閉。
trace
/trace 接口能報(bào)告所有Web請(qǐng)求的詳細(xì)信息,包括請(qǐng)求方法、路徑、時(shí)間戳以及請(qǐng)求和響應(yīng)的頭信息,記錄每一次請(qǐng)求的詳細(xì)信息。
啟動(dòng)示例項(xiàng)目,先訪問(wèn)一次: http://localhost:8080/hello ,再到瀏覽器執(zhí)行: http://localhost:8088/monitor/trace 查看返回信息:
[
{
"timestamp": 1516780334777,
"info": {
"method": "GET",
"path": "/hello",
"headers": {
"request": {
"host": "localhost:8080",
"connection": "keep-alive",
"cache-control": "max-age=0",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36",
"upgrade-insecure-requests": "1",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cookie": "UM_distinctid=16053ba344f1cd-0dc220c44cc94-b7a103e-13c680-16053ba3450751; Hm_lvt_0fb30c642c5f6453f17d881f529a1141=1513076406,1514961720,1515649377; CNZZDATA1260945749=232252692-1513233181-%7C1516085149; Hm_lvt_6d8e8bb59814010152d98507a18ad229=1515247964,1515296008,1515672972,1516086283"
},
"response": {
"X-Application-Context": "application:8080",
"Content-Type": "text/html;charset=UTF-8",
"Content-Length": "11",
"Date": "Wed, 24 Jan 2018 07:52:14 GMT",
"status": "200"
}
},
"timeTaken": "4"
}
}
]
上述信息展示了,/hello請(qǐng)求的詳細(xì)信息。
其它配置
敏感信息訪問(wèn)限制
根據(jù)上面表格,鑒權(quán)為false的,表示不敏感,可以隨意訪問(wèn),否則就是做了一些保護(hù),不能隨意訪問(wèn)。
endpoints.mappings.sensitive=false
這樣需要對(duì)每一個(gè)都設(shè)置,比較麻煩。敏感方法默認(rèn)是需要用戶擁有ACTUATOR角色,因此,也可以設(shè)置關(guān)閉安全限制:
management.security.enabled=false
或者配合Spring Security做細(xì)粒度控制。
啟用和禁用接口
雖然Actuator的接口都很有用,但你不一定需要全部這些接口。默認(rèn)情況下,所有接口(除 了/shutdown)都啟用。比如要禁用 /metrics 接口,則可以設(shè)置如下:
endpoints.metrics.enabled = false
如果你只想打開(kāi)一兩個(gè)接口,那就先禁用全部接口,然后啟用那幾個(gè)你要的,這樣更方便。
endpoints.enabled = false endpoints.metrics.enabled = true
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Springboot集成Actuator監(jiān)控功能詳解
- SpringBoot監(jiān)控模塊Actuator的用法詳解
- SpringBoot2開(kāi)啟Actuator端點(diǎn)監(jiān)控的方法
- SpringBoot 指標(biāo)監(jiān)控actuator的專題
- springboot Actuator的指標(biāo)監(jiān)控可視化功能詳解
- 基于SpringBoot應(yīng)用監(jiān)控Actuator安全隱患及解決方式
- Springboot actuator應(yīng)用后臺(tái)監(jiān)控實(shí)現(xiàn)
- 使用SpringBoot Actuator監(jiān)控應(yīng)用示例
- 詳解關(guān)于springboot-actuator監(jiān)控的401無(wú)權(quán)限訪問(wèn)
- SpringBoot Actuator監(jiān)控的項(xiàng)目實(shí)踐
相關(guān)文章
基于java servlet過(guò)濾器和監(jiān)聽(tīng)器(詳解)
下面小編就為大家?guī)?lái)一篇基于java servlet過(guò)濾器和監(jiān)聽(tīng)器(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
詳解JDK 5 Annotation 注解之@Target的用法介紹
這篇文章主要介紹了詳解JDK 5 Annotation 注解之@Target的用法介紹,需要的朋友可以參考下2016-02-02
解決JD-GUI for mac big sur打不開(kāi)問(wèn)題
這篇文章主要介紹了解決JD-GUI for mac big sur打不開(kāi)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
Spring事務(wù)執(zhí)行流程及如何創(chuàng)建事務(wù)
這篇文章主要介紹了Spring事務(wù)執(zhí)行流程及如何創(chuàng)建事務(wù),幫助大家更好的理解和學(xué)習(xí)使用spring框架,感興趣的朋友可以了解下2021-03-03
詳解SpringMVC學(xué)習(xí)系列之國(guó)際化
這篇文章主要介紹了詳解SpringMVC學(xué)習(xí)系列之國(guó)際化,詳細(xì)的介紹了關(guān)于瀏覽器,Session,Cookie,URL請(qǐng)求的國(guó)際化的實(shí)現(xiàn),有興趣的可以了解一下2017-07-07
Mybatis-Plus-AutoGenerator 最詳細(xì)使用方法
這篇文章主要介紹了Mybatis-Plus-AutoGenerator 最詳細(xì)使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
Spring Data + Thymeleaf 3 + Bo
本篇文章主要介紹了Spring Data + Thymeleaf 3 + Bootstrap 4 實(shí)現(xiàn)分頁(yè)器實(shí)例代碼,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-05-05

