一、Actuator簡介
1、監控組件作用
在生產環境中,需要即時或定期監控服務的可用性。 Spring Boot的actuator(健康監控)功能提供了許多監控所需的接口,可以對應用系統進行配置檢視、相關功能統計等。
2、監控分類
Actuator 提供Rest接口,展示監控資訊。
介面分為三大類:
應用程式配置類別:取得應用程式中載入的應用程式配置、環境變數、自動化配置報告等與SpringBoot應用程式相關的配置類別資訊。
度量指標類別:取得應用程式運行過程中用於監控的度量指標,例如:記憶體資訊、執行緒池資訊、HTTP請求統計量等。
操作控制類別:提供了對應用程式的關閉等操作類別功能。
二、與SpringBoot2.0整合
1、核心依賴Jar套件
<!-- 监控依赖 --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-actuator</artifactid> </dependency>
2、Yml設定檔
# 端口 server: port: 8016 spring: application: # 应用名称 name: node16-boot-actuator management: endpoints: web: exposure: # 打开所有的监控点 include: "*" # 自定义监控路径 monitor # 默认值:http://localhost:8016/actuator/* # 配置后:http://localhost:8016/monitor/* base-path: /monitor endpoint: health: show-details: always shutdown: # 通过指定接口关闭 SpringBoot enabled: true # 可以自定义端口 # server: # port: 8089 # 描述项目基础信息 info: app: name: node16-boot-actuator port: 8016 version: 1.0.0 author: cicada
三、監控介面詳解
1、Info介面
Yml檔案中設定的專案基礎資訊
路径:http://localhost:8016/monitor/info 输出: { "app": { "name": "node16-boot-actuator", "port": 8016, "version": "1.0.0", "author": "cicada" } }
2、Health介面
health 主要用來檢查應用程式的運作狀態
路径:http://localhost:8016/monitor/health 输出: { "status": "UP", "details": { "diskSpace": { "status": "UP", "details": { "total": 185496236032, "free": 140944084992, "threshold": 10485760 } } } }
3、Beans介面
展示了bean 的類型、單例多例、別名、類別的全路徑、依賴Jar等內容。
路径:http://localhost:8016/monitor/beans 输出: { "contexts": { "node16-boot-actuator": { "beans": { "endpointCachingOperationInvokerAdvisor": { "aliases": [], "scope": "singleton", "type": "org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor", "resource": "class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]", "dependencies": ["environment"] } } } }
4、Conditions介面
查看配置在什麼條件下有效,或自動設定為什麼無效。
路径:http://localhost:8016/monitor/conditions 输出: { "contexts": { "node16-boot-actuator": { "positiveMatches": { "AuditAutoConfiguration#auditListener": [{ "condition": "OnBeanCondition", "message": "@ConditionalOnMissingBean" }], } }
5、HeapDump介面
自動產生Jvm的堆轉儲檔案HeapDump,可以使用監控工具 VisualVM 開啟此檔案檢視記憶體快照。
路径:http://localhost:8016/monitor/heapdump
6、Mappings介面
描述URI 路徑與控制器的對應關係
路径:http://localhost:8016/monitor/mappings 输出: { "contexts": { "node16-boot-actuator": { "mappings": { "dispatcherServlets": { "dispatcherServlet": [ { "handler": "Actuator web endpoint 'auditevents'", "predicate": "{GET /monitor/auditevents || application/json]}", "details": { "handlerMethod": { "className": "org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping.Operat "name": "handle", "descriptor": "(Ljavax/servlet/http/HttpServletRequest;Ljava/util/Map;)Ljava/lang/Object;" }, "requestMappingConditions": { "consumes": [], "headers": [], "methods": ["GET"], "params": [], "patterns": ["/monitor/auditevents"], "produces": [{ "mediaType": "application/vnd.spring-boot.actuator.v2+json", "negated": false }, { "mediaType": "application/json", "negated": false }] } } } } } }
7、ThreadDump介面
展示執行緒名稱、執行緒ID、是否等待鎖、執行緒的狀態、執行緒鎖等相關資訊。
路径:http://localhost:8016/monitor/threaddump 输出: { "threads": [{ "threadName": "DestroyJavaVM", "threadId": 34, "blockedTime": -1, "blockedCount": 0, "waitedTime": -1, "waitedCount": 0, "lockName": null, "lockOwnerId": -1, "lockOwnerName": null, "inNative": false, "suspended": false, "threadState": "RUNNABLE", "stackTrace": [], "lockedMonitors": [], "lockedSynchronizers": [], "lockInfo": null } ] }
以上是SpringBoot2中如何配置Actuator元件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

JVM通過JavaNativeInterface(JNI)和Java標準庫處理操作系統API差異:1.JNI允許Java代碼調用本地代碼,直接與操作系統API交互。 2.Java標準庫提供統一API,內部映射到不同操作系統API,確保代碼跨平台運行。

modularitydoesnotdirectlyaffectJava'splatformindependence.Java'splatformindependenceismaintainedbytheJVM,butmodularityinfluencesapplicationstructureandmanagement,indirectlyimpactingplatformindependence.1)Deploymentanddistributionbecomemoreefficientwi

BytecodeinJavaistheintermediaterepresentationthatenablesplatformindependence.1)Javacodeiscompiledintobytecodestoredin.classfiles.2)TheJVMinterpretsorcompilesthisbytecodeintomachinecodeatruntime,allowingthesamebytecodetorunonanydevicewithaJVM,thusfulf

javaachievesplatformIndependencEthroughThoJavavIrtualMachine(JVM),wodecutesbytecodeonyanydenanydevicewithajvm.1)javacodeiscompiledintobytecode.2)

JavaGUI開發中的平台獨立性面臨挑戰,但可以通過使用Swing、JavaFX,統一外觀,性能優化,第三方庫和跨平台測試來應對。 JavaGUI開發依賴於AWT和Swing,Swing旨在提供跨平台一致性,但實際效果因操作系統不同而異。解決方案包括:1)使用Swing和JavaFX作為GUI工具包;2)通過UIManager.setLookAndFeel()統一外觀;3)優化性能以適應不同平台;4)使用如ApachePivot或SWT的第三方庫;5)進行跨平台測試以確保一致性。

JavadevelovermentIrelyPlatForm-DeTueTososeVeralFactors.1)JVMVariationsAffectPerformanceNandBehaviorAcroSsdifferentos.2)Nativelibrariesviajnijniiniininiinniinindrododerplatefform.3)

Java代碼在不同平台上運行時會有性能差異。 1)JVM的實現和優化策略不同,如OracleJDK和OpenJDK。 2)操作系統的特性,如內存管理和線程調度,也會影響性能。 3)可以通過選擇合適的JVM、調整JVM參數和代碼優化來提升性能。

Java'splatFormentenceHaslimitations不包括PerformanceOverhead,versionCompatibilityIsissues,挑戰WithnativelibraryIntegration,Platform-SpecificFeatures,andjvminstallation/jvminstallation/jvmintenance/jeartenance.therefactorscomplicatorscomplicatethe“ writeOnce”


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

Dreamweaver Mac版
視覺化網頁開發工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!