日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringBoot 监控

發布時間:2024/3/12 javascript 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot 监控 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SpringBoot 監控

監控主要介紹兩個:Actuator和 Spring Boot Admin

Actuator

一,Actuator簡介

Actuator是spring boot的一個附加功能,可幫助你在應用程序生產環境時監視和管理應用程序。可以使用HTTP的各種請求來監管,審計,收集應用的運行情況。Spring Boot Actuator提供了對單個Spring Boot的監控,信息包含:應用狀態、內存、線程、堆棧等等,比較全面的監控了SpringBoot應用的整個生命周期。特別對于微服務管理十分有意義。

二,Actuator 的 REST 接口

Actuator 監控分成兩類:原生端點和用戶自定義端點;自定義端點主要是指擴展性,用戶可以根
據自己的實際應用,定義一些比較關心的指標,在運行期進行監控。原生端點是在應用程序里提供眾多 Web 接口,通過它們了解應用程序運行時的內部狀況。原生端點又可以分成三類:
應用配置類:可以查看應用在運行期的靜態信息:例如自動配置信息、加載的 springbean
信息、yml 文件配置信息、環境信息、請求映射信息;
度量指標類:主要是運行期的動態信息,例如堆棧、請求鏈、一些健康指標、metrics 信息
等;
操作控制類:主要是指 shutdown,用戶可以發送一個請求將應用的監控功能關閉。Actuator 提供了 13 個接口,具體如下表所示。

三,體驗Actuator

使用Actuator功能與springBoot使用其他功能一樣簡單,只需要在pom.xml中添加如下依賴:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId> </dependency>

為了保證 actuator 暴露的監控接口的安全性,需要添加安全控制的依賴 spring-boot-startsecurity 依賴,訪問應用監控端點時,都需要輸入驗證信息。Security 依賴,可以選擇不加,不進行安全管理
配置文件

#自己配置在配置文件中以 info 開頭的配置信息,比如我們在示例項目中的配置是: info.app.name=spring-boot-actuator info.app.version= 1.0.0 info.app.test=test #在 Spring Boot 2.x 中為了安全期間,Actuator 只開放了兩個端點 /actuator/health和/actuator/info。可以在配置文件中設置打開,*號配置的是打開所有。 management.endpoints.web.exposure.include=* # 也可以配置打開部分 #management.endpoints.web.exposure.include=beans,trace #展示細節,除了always之外還有when-authorized、never,默認值是never management.endpoint.health.show-details=always #Actuator 默認所有的監控點路徑都在 /actuator/* ,當然如果有需要這個路徑也支持定制。 #management.endpoints.web.base-path=/monitor #啟用接口關閉 Spring Boot配置完成之后,啟動項目就可以繼續驗證各個監控功能了。 management.endpoint.shutdown.enabled=true

訪問ip:port/actuator/接口名即可(想顯示json格式需要谷歌安裝一個json插件)

Spring Boot Admin

一,springboot admin簡介

對于spring actuator而言,最大的缺點在于是以json形式來進行展示,為了更好的進行監控
顯示,我們來介紹一個更加方便的工具:spring boot admin(可視化后臺管理系統)。
Spring Boot Admin 是一個針對spring-boot的actuator接口進行UI美化封裝的監控工具。他可以返回在列表中瀏覽所有被監控spring-boot項目的基本信息比如:Spring容器管理的所有的bean、詳細的Health信息、內存信息、JVM信息、垃圾回收信息、各種配置信息(比如數據源、緩存列表和命中率)等,Threads 線程管理,Environment 管理等。
利用springbootadmin進行監控的架構圖如下:

二,搭建Server端

pom.xml

<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>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId> </dependency>

applicaiton.yml

server:port: 8081 @EnableAdminServer @SpringBootApplication public class App {public static void main(String[] args) {SpringApplication.run(App.class, args); }

啟動服務端:localhost:8081

三,搭建client端

pom.xml

<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>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId> <version>2.1.0</version> </dependency>

application.yml

server:port: 8080 #自定義配置信息用于"/actuator/info"讀取 info:name: 老王age: 100phone: 110 #通過下面的配置啟用所有的監控端點,默認情況下,這些端點是禁用的; management:endpoints:#app.java#啟動 client……#幾秒后刷新,可以看到 client 端已注冊到 server。#查看 client 詳細信息:web:exposure:inclued: "*"endpoint:health:show-details: always ## 將Client作為服務注冊到Server,通過Server來監聽項目的運行情況 spring:boot:admin:client:url: http://localhost:8081 ##application實例名 application:name: spring-boot-admin-client

啟動 client……
幾秒后刷新,可以看到 client 端已注冊到 server。


在使用過程中出現過這樣一個問題,client端啟動后server端報錯,去client里邊配置一下server.address就可以了

總結

以上是生活随笔為你收集整理的SpringBoot 监控的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。