Spring Boot 項(xiàng)目做性能監(jiān)控的操作流程
Spring Boot特別適合團(tuán)隊(duì)構(gòu)建各種可快速迭代的微服務(wù),同時(shí)為了減少程序本身監(jiān)控系統(tǒng)的開發(fā)量,Spring Boot 提供了 actuator 模塊,可以很方便的對(duì)你的 Spring Boot 程序做監(jiān)控。
1. actuator接口說明
Spring Boot 應(yīng)用中加入監(jiān)控很簡(jiǎn)單,只需要在pom.xml文件中加入以下依賴:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
為了保證actuator接口的敏感性,在配置文件中,開放安全屬性配置:
management.security.enabled=false
這樣就能允許你查看 Spring Boot 進(jìn)程的actuator信息了。
啟動(dòng)Spring Boot程序,在啟動(dòng)日志里看到可訪問的actuator接口:
通過這些,我們可以實(shí)時(shí)的獲取應(yīng)用的各項(xiàng)監(jiān)控指標(biāo)。另外,關(guān)注微信公眾號(hào):Java技術(shù)棧,在后臺(tái)回復(fù):boot,可以獲取我整理的 N 篇 Spring Boot 教程,都是干貨。
actuator的接口分為原生接口和用戶自定義接口。原生接口主要有如下幾個(gè):
如果你想關(guān)閉某個(gè)接口,比如關(guān)閉health接口,可以直接設(shè)置:
endpoints.health.enabled=false
2. 監(jiān)控展示
2.1 JConsole
JConsole是一個(gè)內(nèi)置Java性能分析器,如果你本機(jī)已經(jīng)配置了jdk的話,可直接命令行輸入jconsole,打開后的頁面如下圖所示:
選擇你要監(jiān)控的進(jìn)程,點(diǎn)擊連接即可進(jìn)入該Java進(jìn)程的監(jiān)控首頁,如下圖所示:
可以很詳細(xì)地展示進(jìn)程的內(nèi)存、CPU、類信息。
2.2 Spring Boot Admin
Spring Boot Admin是一款監(jiān)控和管理 Spring Boot 應(yīng)用程序的開源軟件。Spring Boot Admin讀取actuator的接口數(shù)據(jù),并通過 Spring Boot Admin UI 將實(shí)時(shí)數(shù)據(jù)展示在前端。
創(chuàng)建一個(gè)Spring Boot Admin Server,首先需要?jiǎng)?chuàng)建一個(gè)基本的 Spring Boot 應(yīng)用程序,這個(gè)就不做贅述了,并加入以下依賴:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.5.7</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.5.7</version> </dependency>
server.port端口設(shè)置為8090,并注冊(cè)到你的eureka服務(wù)上。
啟動(dòng)類中使用注解開啟服務(wù):
@SpringBootApplication @EnableDiscoveryClient @EnableAdminServer @EnableTurbine public class HtsApplication { public static void main(String[] args) { SpringApplication.run(HtsApplication.class, args); } }
瀏覽器訪問:http://localhost:8090 即可看到如下Spring Boot Admin Server的頁面:
在任意需要被監(jiān)控的Spring Boot應(yīng)用程序上,添加依賴:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>1.5.7</version> </dependency>
啟動(dòng)客戶端后,稍等片刻,Spring Boot Admin Server從Eureka上拿到注冊(cè)信息后,即可在 http://localhost:8090 上看到應(yīng)用程序的監(jiān)控信息了:
3. FAQ
Spring Boot Admin Server上可以配置郵件告警信息,添加自己的Email即可收到告警信息。 Spring Boot Admin Server監(jiān)控的應(yīng)用程序服務(wù),需要和Spring Boot Admin Server都注冊(cè)到Eureka上。推薦去我的博客閱讀更多:
1.Java JVM、集合、多線程、新特性系列教程
2.Spring MVC、Spring Boot、Spring Cloud 系列教程
3.Maven、Git、Eclipse、Intellij IDEA 系列工具教程
4.Java、后端、架構(gòu)、阿里巴巴等大廠最新面試題
到此這篇關(guān)于Spring Boot 項(xiàng)目如何做性能監(jiān)控的文章就介紹到這了,更多相關(guān)Spring Boot性能監(jiān)控內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Python 實(shí)現(xiàn)勞拉游戲的實(shí)例代碼(四連環(huán)、重力四子棋)2. python 寫函數(shù)在一定條件下需要調(diào)用自身時(shí)的寫法說明3. Java GZip 基于內(nèi)存實(shí)現(xiàn)壓縮和解壓的方法4. java獲取文件編碼,jsoup獲取html純文本操作5. 淺談Android Studio導(dǎo)出javadoc文檔操作及問題的解決6. 利用CSS制作3D動(dòng)畫7. 一款功能強(qiáng)大的markdown編輯器tui.editor使用示例詳解8. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼9. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))10. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程
