spring監(jiān)視器actuator配置應(yīng)用
引入依賴(lài)
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>3.1.0</version> </dependency>
配置
# actuator # 將所有路徑都加入監(jiān)視 management.endpoints.web.exposure.include=* # 將某幾個(gè)路徑取消監(jiān)控 management.endpoints.web.exposure.exclude=info,caches
應(yīng)用
自帶的路徑
localhost:8080/mycommunity/actuator/health
自定義路徑
@Component @Endpoint(id = "database") public class DatabaseEndpoint { private static final Logger logger = LoggerFactory.getLogger(DatabaseEndpoint.class); @Autowired private DataSource dataSource; // readOperation means this method can only be accessed by get request // writeOperation means this method can only be accessed by post request @ReadOperation public String checkConnection(){ try( Connection connection = dataSource.getConnection(); ) { return CommunityUtil.getJSONString(0,"success"); } catch (SQLException e) { e.printStackTrace(); logger.error("failed"); } return CommunityUtil.getJSONString(1, "failed"); } }
訪問(wèn)瀏覽器:localhost:8080/mycommunity/actuator/database
注意actuator路徑只能對(duì)管理員訪問(wèn),注意做權(quán)限管理
到此這篇關(guān)于spring監(jiān)視器actuator的文章就介紹到這了,更多相關(guān)spring監(jiān)視器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mybatis開(kāi)啟控制臺(tái)打印sql語(yǔ)句方式
這篇文章主要介紹了Mybatis開(kāi)啟控制臺(tái)打印sql語(yǔ)句方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07SpringBoot實(shí)現(xiàn)發(fā)送郵件功能過(guò)程圖解
這篇文章主要介紹了SpringBoot實(shí)現(xiàn)發(fā)送郵件功能過(guò)程圖解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03Lambda表達(dá)式下訪問(wèn)外部變量問(wèn)題
這篇文章主要介紹了Lambda表達(dá)式下訪問(wèn)外部變量問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11springboot集成elasticsearch7的圖文方法
本文記錄springboot集成elasticsearch7的方法,本文通過(guò)圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友參考下吧2021-05-05Mybatis Limit實(shí)現(xiàn)分頁(yè)功能
這篇文章主要介紹了Mybatis Limit實(shí)現(xiàn)分頁(yè)功能,使用Limit實(shí)現(xiàn)分頁(yè)可以減少數(shù)據(jù)的處理量,本文通過(guò)代碼講解的非常詳細(xì),需要的朋友可以參考下2021-04-04使用Springboot實(shí)現(xiàn)OAuth服務(wù)的示例詳解
OAuth(Open Authorization)是一個(gè)開(kāi)放標(biāo)準(zhǔn),用于授權(quán)第三方應(yīng)用程序訪問(wèn)用戶(hù)資源,而不需要共享用戶(hù)憑證。本文主要介紹了如何使用Springboot實(shí)現(xiàn)一個(gè)OAuth服務(wù),需要的可以參考一下2023-05-05