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

歡迎訪問 生活随笔!

生活随笔

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

javascript

Spring Boot Admin:微服务应用监控

發布時間:2024/10/6 javascript 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Boot Admin:微服务应用监控 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

摘要


Spring Boot Admin 可以對SpringBoot應用的各項指標進行監控,可以作為微服務架構中的監控中心來使用,本文將對其用法進行詳細介紹。

Spring Boot Admin 簡介


SpringBoot應用可以通過Actuator來暴露應用運行過程中的各項指標,Spring Boot Admin通過這些指標來監控SpringBoot應用,然后通過圖形化界面呈現出來。Spring Boot Admin不僅可以監控單體應用,還可以和Spring Cloud的注冊中心相結合來監控微服務應用。
Spring Boot Admin 可以提供應用的以下監控信息:

監控應用運行過程中的概覽信息;
度量指標信息,比如JVM、Tomcat及進程信息;
環境變量信息,比如系統屬性、系統環境變量以及應用配置信息;
查看所有創建的Bean信息;
查看應用中的所有配置信息;
查看應用運行日志信息;
查看JVM信息;
查看可以訪問的Web端點;
查看HTTP跟蹤信息。

創建admin-server模塊


這里我們創建一個admin-server模塊來作為監控中心演示其功能。

  • 在pom.xml中添加相關依賴:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId> </dependency>
  • 在application.yml中進行配置:
spring:application:name: admin-server server:port: 9301
  • 在啟動類上添加@EnableAdminServer來啟用admin-server功能:
@EnableAdminServer @SpringBootApplication public class AdminServerApplication {public static void main(String[] args) {SpringApplication.run(AdminServerApplication.class, args);}}

創建admin-client模塊


這里我們創建一個admin-client模塊作為客戶端注冊到admin-server。

  • 在pom.xml中添加相關依賴:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId> </dependency>
  • 在application.yml中進行配置:
spring:application:name: admin-clientboot:admin:client:url: http://localhost:9301 #配置admin-server地址 server:port: 9305 management:endpoints:web:exposure:include: '*'endpoint:health:show-details: always logging:file: admin-client.log #添加開啟admin的日志監控

監控信息演示


  • 訪問如下地址打開Spring Boot Admin的主頁:http://localhost:9301
  • 點擊wallboard按鈕,選擇admin-client查看監控信息;
  • 監控信息概覽;
  • 度量指標信息,比如JVM、Tomcat及進程信息;
  • 環境變量信息,比如系統屬性、系統環境變量以及應用配置信息;
  • 查看所有創建的Bean信息;
  • 查看應用中的所有配置信息;
  • 查看日志信息,需要添加以下配置才能開啟;
logging:file: admin-client.log #添加開啟admin的日志監控

  • 查看JVM信息;

  • 查看可以訪問的Web端點;

  • 查看HTTP跟蹤信息;

結合注冊中心使用

Spring Boot Admin結合Spring Cloud 注冊中心使用,只需將admin-server和注冊中心整合即可,admin-server 會自動從注冊中心獲取服務列表,然后挨個獲取監控信息。這里以Eureka注冊中心為例來介紹下該功能。

修改admin-server
  • 在pom.xml中添加相關依賴:
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
  • 在application-eureka.yml中進行配置,只需添加注冊中心配置即可:
spring:application:name: admin-server server:port: 9301 eureka:client:register-with-eureka: truefetch-registry: trueservice-url:defaultZone: http://localhost:8001/eureka/
  • 在啟動類上添加@EnableDiscoveryClient來啟用服務注冊功能:
@EnableDiscoveryClient @EnableAdminServer @SpringBootApplication public class AdminServerApplication {public static void main(String[] args) {SpringApplication.run(AdminServerApplication.class, args);}}
修改admin-client
  • 在pom.xml中添加相關依賴:
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
  • 在application-eureka.yml中進行配置,刪除原來的admin-server地址配置,添加注冊中心配置即可:
spring:application:name: admin-client server:port: 9305 management:endpoints:web:exposure:include: '*'endpoint:health:show-details: always logging:file: admin-client.log #添加開啟admin的日志監控 eureka:client:register-with-eureka: truefetch-registry: trueservice-url:defaultZone: http://localhost:8001/eureka/
  • 在啟動類上添加@EnableDiscoveryClient來啟用服務注冊功能:
@EnableDiscoveryClient @SpringBootApplication public class AdminClientApplication {public static void main(String[] args) {SpringApplication.run(AdminClientApplication.class, args);}}
功能演示
  • 啟動eureka-server,使用application-eureka.yml配置啟動admin-server,admin-client;
  • 查看注冊中心發現服務均已注冊:http://localhost:8001/
  • 查看Spring Boot Admin 主頁發現可以看到服務信息:http://localhost:9301

添加登錄認證


我們可以通過給admin-server添加Spring Security支持來獲得登錄認證功能。

創建admin-security-server模塊
  • 在pom.xml中添加相關依賴:
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.1.5</version> </dependency> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId> </dependency>
  • 在application.yml中進行配置,配置登錄用戶名和密碼,忽略admin-security-server的監控信息:
spring:application:name: admin-security-serversecurity: # 配置登錄用戶名和密碼user:name: macropassword: 123456boot: # 不顯示admin-security-server的監控信息admin:discovery:ignored-services: ${spring.application.name} server:port: 9301 eureka:client:register-with-eureka: truefetch-registry: trueservice-url:defaultZone: http://localhost:8001/eureka/
  • 對SpringSecurity進行配置,以便admin-client可以注冊:
/*** Created by macro on 2019/9/30.*/ @Configuration public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {private final String adminContextPath;public SecuritySecureConfig(AdminServerProperties adminServerProperties) {this.adminContextPath = adminServerProperties.getContextPath();}@Overrideprotected void configure(HttpSecurity http) throws Exception {SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();successHandler.setTargetUrlParameter("redirectTo");successHandler.setDefaultTargetUrl(adminContextPath + "/");http.authorizeRequests()//1.配置所有靜態資源和登錄頁可以公開訪問.antMatchers(adminContextPath + "/assets/**").permitAll().antMatchers(adminContextPath + "/login").permitAll().anyRequest().authenticated().and()//2.配置登錄和登出路徑.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and().logout().logoutUrl(adminContextPath + "/logout").and()//3.開啟http basic支持,admin-client注冊時需要使用.httpBasic().and().csrf()//4.開啟基于cookie的csrf保護.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())//5.忽略這些路徑的csrf保護以便admin-client注冊.ignoringAntMatchers(adminContextPath + "/instances",adminContextPath + "/actuator/**");} }
  • 修改啟動類,開啟AdminServer及注冊發現功能:
@EnableDiscoveryClient @EnableAdminServer @SpringBootApplication public class AdminSecurityServerApplication {public static void main(String[] args) {SpringApplication.run(AdminSecurityServerApplication.class, args);}}
  • 啟動eureka-server,admin-security-server,訪問Spring Boot Admin 主頁發現需要登錄才能訪問:http://localhost:9301

使用到的模塊

springcloud-learning ├── eureka-server -- eureka注冊中心 ├── admin-server -- admin監控中心服務 ├── admin-client -- admin監控中心監控的應用服務 └── admin-security-server -- 帶登錄認證的admin監控中心服務

項目源碼地址

https://github.com/macrozheng/springcloud-learning

總結

以上是生活随笔為你收集整理的Spring Boot Admin:微服务应用监控的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 污污的视频网站在线观看 | 中文在线观看视频 | 亚洲黄色激情视频 | 日韩第一页在线观看 | 久久久夜夜 | 中文字幕在线观看精品 | 日本在线精品 | 男人天堂国产 | 麻豆免费下载 | 人人草人人搞 | 在线视频久久 | 国产视频不卡一区 | av高清一区 | 色女人综合 | 成年人网站av | 国产精品综合在线 | 性渴老太作爱 | 国产激情网站 | 韩国三级国产 | 天天干夜夜欢 | 日本午夜大片 | 新av在线 | 国产中文字幕三区 | 亚洲欧美日韩精品永久在线 | 亚洲成a人片77777精品 | 99视频久 | 丰满人妻av一区二区三区 | 玉足调教丨vk24分钟 | 老男人av| 日本一二三区在线视频 | 在线观看av国产一区二区 | 日本泡妞视频 | 我要操婊| 国产日韩av在线 | 耳光调教vk | 亚洲精品久久久久久动漫器材一区 | www欧美精品 | 女性生殖扒开酷刑vk | 国产精品无码无卡无需播放器 | 欧美日韩一卡二卡 | 91香蕉视频污污 | 美女黄色一级视频 | 中文在线a√在线8 | 一区二区三区波多野结衣 | julia一区二区三区中文字幕 | 日韩小视频网站 | 日韩一区二区三区精品视频 | 久久久久国产免费 | 四虎国产成人永久精品免费 | 精品人伦一区二区三电影 | 嫩草国产在线 | 亚洲精品一区二区在线 | 国产成人一级片 | 精品深夜av无码一区二区老年 | 青娱乐国产视频 | 91精品欧美一区二区三区 | 久久久久一级片 | 青春草国产视频 | japanese av在线 | 精品欧美一区二区三区免费观看 | 色先锋av资源 | 青草青视频 | 伊人国产在线观看 | 永久免费精品 | 黄色羞羞网站 | 少妇被按摩师摸高潮了 | 免费黡色av | 精品国产成人av | 永久精品网站 | 在线香蕉视频 | 免费超碰在线观看 | 久久久久久久91 | 小珊的性放荡羞辱日记 | a无一区二区三区 | 极品人妻videosss人妻 | 正在播放老肥熟妇露脸 | 5566色| 欧美性xxxxx极品少妇 | 在线免费观看一区二区三区 | 国产日韩欧美电影 | 91video| 国产精品一区二区三区四区五区 | www.色综合 | 成年人免费在线观看 | 2020国产在线 | 三级精品在线 | 欧美福利视频在线观看 | 免费萌白酱国产一区二区三区 | 日本人妻丰满熟妇久久久久久 | 性猛交ⅹxxx富婆video | 久久久久久91香蕉国产 | 色综合天天综合网天天狠天天 | 九色91av | 欧美日韩精品一区二区在线观看 | 国产精品国产三级国产播12软件 | 伊人婷婷综合 | 强迫凌虐淫辱の牝奴在线观看 | 国产成人无码精品久久久久 | 国模婷婷 |