最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot+actuator和admin-UI實(shí)現(xiàn)監(jiān)控中心方式

 更新時(shí)間:2024年05月21日 10:57:39   作者:螞蟻舞  
這篇文章主要介紹了SpringBoot+actuator和admin-UI實(shí)現(xiàn)監(jiān)控中心方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

使用SpringBoot很久了,但是很少使用到SpringBoot的查看和監(jiān)控,將來(lái)八成也不會(huì)用到,萬(wàn)一有機(jī)會(huì)用到呢?

所以記錄一下以前學(xué)習(xí)SpringBoot+actuator和adminUI實(shí)現(xiàn)監(jiān)控中心的方式

Springboot的版本2.0.x

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.0.5.RELEASE</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>

導(dǎo)入對(duì)應(yīng)的包

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

<!-- security 一旦導(dǎo)入就會(huì)生效 -->
<!--
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-security</artifactId>
</dependency>
 
<dependency>
	<groupId>org.springframework.security</groupId>
	<artifactId>spring-security-test</artifactId>
	<scope>test</scope>
</dependency>
 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

application.properties


server.port=7080

# 配置用戶名和密碼
#spring.security.user.name=admin
#spring.security.user.password=123456

# 端點(diǎn)信息配置
management.server.port=8081
management.server.servlet.context-path=/sys
# 默認(rèn) never always可以顯示硬盤使用情況和線程情況
management.endpoint.health.show-details=always
# 端點(diǎn)暴露的內(nèi)容,默認(rèn)["health","info"],設(shè)置"*"代表暴露所有可訪問(wèn)的端點(diǎn)
management.endpoints.web.exposure.include=*

# actuator 信息
info.actuator.name=test

啟動(dòng)之后

myw

訪問(wèn)

http://localhost:8081/sys/actuator

myw

在這里使用的Actuator是spring boot的一個(gè)附加功能,可幫助你在應(yīng)用程序生產(chǎn)環(huán)境時(shí)監(jiān)視和管理應(yīng)用程序。

可以使用HTTP的各種請(qǐng)求來(lái)監(jiān)管,審計(jì),收集應(yīng)用的運(yùn)行情況.特別對(duì)于微服務(wù)管理十分有意義.

缺點(diǎn):沒(méi)有可視化界面

使用場(chǎng)景,針對(duì)微服務(wù)的服務(wù)狀態(tài)監(jiān)控,服務(wù)器的內(nèi)存變化(堆內(nèi)存,線程,日志管理等),檢測(cè)服務(wù)配置連接地址是否可用(模擬訪問(wèn),懶加載),統(tǒng)計(jì)現(xiàn)在有多少個(gè)bean(Spring容器中的bean) 統(tǒng)計(jì)接口數(shù)量,

應(yīng)用場(chǎng)景:生產(chǎn)環(huán)境

  • /actuator/beans 顯示應(yīng)用程序中所有Spring bean的完整列表
  • /actuator/configprops 顯示所有配置信息
  • /actuator/env 陳列所有的環(huán)境變量
  • /actuator/mappings 顯示所有@RequestMapping的url整理列表
  • /actuator/health 顯示應(yīng)用程序運(yùn)行狀況信息 up表示成功 down失敗,對(duì)于懶加載沒(méi)報(bào)錯(cuò)的可以看到控制臺(tái)報(bào)錯(cuò)了
  • /actuator/info 查看自定義應(yīng)用信息

懶加載有個(gè)缺點(diǎn),例如mysql的配置,啟動(dòng)的時(shí)候不會(huì)發(fā)現(xiàn)錯(cuò)誤,只有運(yùn)行的時(shí)候才報(bào)錯(cuò)

當(dāng)訪問(wèn)

http://localhost:8081/sys/actuator/health

myw

使用adminUI的方式 client客戶端導(dǎo)包和配置

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

application.properties

server.port=8071

spring.application.name=boot-example-admin-client

spring.boot.admin.client.url=http://127.0.0.1:8050/myw-admin
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456
spring.boot.admin.client.instance.service-url=http://127.0.0.1:8071

#management.server.port=8081
#management.server.servlet.context-path=/sys
# 默認(rèn) never always可以顯示硬盤使用情況和線程情況
management.endpoint.health.show-details=always
# 端點(diǎn)暴露的內(nèi)容,默認(rèn)["health","info"],設(shè)置"*"代表暴露所有可訪問(wèn)的端點(diǎn)
management.endpoints.web.exposure.include=*

使用admin-ui的方式 server服務(wù)端導(dǎo)包和配置

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

application.properties


server.port=8050
server.servlet.context-path=/myw-admin
spring.application.name=boot-example-admin-server

spring.security.user.name=admin
spring.security.user.password=123456


WebSecurityConfig.java

package boot.example.admin.server;

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;

/**
 * SpringBootAdmin 登錄鑒權(quán)使用
 *
 */
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    private final String contextPath;

    public WebSecurityConfig(AdminServerProperties adminServerProperties) {
        this.contextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // 跨域設(shè)置,SpringBootAdmin客戶端通過(guò)instances注冊(cè),見(jiàn)InstancesController
        http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers(contextPath + "/instances");

        http.authorizeRequests().antMatchers(contextPath + "/assets/**").permitAll(); // 靜態(tài)資源
        http.authorizeRequests().antMatchers(contextPath + "/actuator/**").permitAll(); // 自身監(jiān)控
        http.authorizeRequests().anyRequest().authenticated(); // 所有請(qǐng)求必須通過(guò)認(rèn)證

        // 整合spring-boot-admin-server-ui
        http.formLogin().loginPage("/login").permitAll();
        http.logout().logoutUrl("/logout").logoutSuccessUrl("/login");

        // 啟用basic認(rèn)證,SpringBootAdmin客戶端使用的是basic認(rèn)證
        http.httpBasic();
    }
}

啟動(dòng)客戶端和服務(wù)端的監(jiān)控中心

http://localhost:8050/myw-admin/login#/applications

myw

myw

myw

記錄一下在SpringBoot2.6.6版本使用

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.6.6</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>

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

application.properties 1

server.port=8071

spring.application.name=boot-example-admin-client1

spring.boot.admin.client.url=http://localhost:8050
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456

management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*


application.properties 2


server.port=8072

spring.application.name=boot-example-admin-client2

spring.boot.admin.client.url=http://localhost:8050
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456

management.server.port=8082
management.server.base-path = /sys
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

application.properties 3


server.port=8073

spring.application.name=boot-example-admin-client3

spring.boot.admin.client.url=http://localhost:8050
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456

#spring.security.user.name=admin
#spring.security.user.password=123456

management.server.port=8083
management.server.base-path = /sys
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

服務(wù)端的配置

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-security</artifactId>
</dependency>

<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>spring-boot-admin-starter-server</artifactId>
	<version>2.5.6</version>
</dependency>

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

application.properties


server.port=8050

spring.application.name=boot-example-admin-server

spring.security.user.name=admin
spring.security.user.password=123456


總結(jié)

備注記錄到這里 將來(lái)會(huì)不會(huì)用到再說(shuō)了。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Java阻塞隊(duì)列(BlockingQueue)的實(shí)現(xiàn)原理

    詳解Java阻塞隊(duì)列(BlockingQueue)的實(shí)現(xiàn)原理

    這篇文章主要介紹了詳解Java阻塞隊(duì)列(BlockingQueue)的實(shí)現(xiàn)原理,阻塞隊(duì)列是Java util.concurrent包下重要的數(shù)據(jù)結(jié)構(gòu),有興趣的可以了解一下
    2017-06-06
  • SpringBoot后端接收多個(gè)文件多種實(shí)現(xiàn)方法

    SpringBoot后端接收多個(gè)文件多種實(shí)現(xiàn)方法

    SpringBoot提供了簡(jiǎn)單的方式來(lái)實(shí)現(xiàn)文件接收功能,可使用MultipartFile來(lái)接收上傳的文件,并將其存儲(chǔ)在服務(wù)器的指定位置,在SpringBoot中接收多個(gè)文件有多種方式,本文將詳細(xì)介紹各種方法及其實(shí)現(xiàn),需要的朋友可以參考下
    2025-09-09
  • SpringBoot返回對(duì)象時(shí),如何將Long類型轉(zhuǎn)換為String

    SpringBoot返回對(duì)象時(shí),如何將Long類型轉(zhuǎn)換為String

    這篇文章主要介紹了SpringBoot返回對(duì)象時(shí),實(shí)現(xiàn)將Long類型轉(zhuǎn)換為String,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • 基于Spring Boot的Environment源碼理解實(shí)現(xiàn)分散配置詳解

    基于Spring Boot的Environment源碼理解實(shí)現(xiàn)分散配置詳解

    這篇文章主要給大家介紹了基于Spring Boot的Environment源碼理解實(shí)現(xiàn)分散配置的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-08-08
  • sentinel整合ribbon與fallback流程分步講解

    sentinel整合ribbon與fallback流程分步講解

    這篇文章主要介紹了sentinel整合ribbon與fallback分步流程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Java畢業(yè)設(shè)計(jì)實(shí)戰(zhàn)項(xiàng)目之寵物商城系統(tǒng)的實(shí)現(xiàn)流程

    Java畢業(yè)設(shè)計(jì)實(shí)戰(zhàn)項(xiàng)目之寵物商城系統(tǒng)的實(shí)現(xiàn)流程

    這是一個(gè)使用了java+Springboot+Maven+mybatis+Vue+mysql開發(fā)的寵物商城系統(tǒng),是一個(gè)畢業(yè)設(shè)計(jì)的實(shí)戰(zhàn)練習(xí),具有寵物商城該有的所有功能,感興趣的朋友快來(lái)看看吧
    2022-01-01
  • 詳解Java?ThreadPoolExecutor的拒絕策略

    詳解Java?ThreadPoolExecutor的拒絕策略

    這篇文章主要介紹了Java?ThreadPoolExecutor的拒絕策略,本文對(duì)于線程的池的幾種策略進(jìn)行詳細(xì)的講解,在實(shí)際的生產(chǎn)中需要集合相關(guān)的場(chǎng)景來(lái)選擇合適的拒絕策略,需要的朋友可以參考下
    2022-08-08
  • java實(shí)現(xiàn)打印日歷

    java實(shí)現(xiàn)打印日歷

    這篇文章主要為大家詳細(xì)介紹了java打印日歷的實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • spring boot hutool整合email的詳細(xì)過(guò)程

    spring boot hutool整合email的詳細(xì)過(guò)程

    這篇文章主要介紹了spring boot hutool整合email的相關(guān)知識(shí),本文介紹兩種方式發(fā)送email文件,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-03-03
  • Java中本地緩存的4種實(shí)現(xiàn)方式總結(jié)

    Java中本地緩存的4種實(shí)現(xiàn)方式總結(jié)

    這篇文章主要介紹了Java中本地緩存的4種實(shí)現(xiàn)方式,分別是基礎(chǔ)緩存實(shí)現(xiàn)、GuavaLoadingCache、SpringBoot整合Caffeine和JetCache,通過(guò)實(shí)例代碼,詳細(xì)講解了每種緩存技術(shù)的特點(diǎn)和使用方法,需要的朋友可以參考下
    2025-04-04

最新評(píng)論

斗六市| 南和县| 大新县| 长岭县| 长垣县| 民权县| 凌源市| 阜新| 开江县| 西乌珠穆沁旗| 潍坊市| 青铜峡市| 怀宁县| 鄂尔多斯市| 永城市| 井研县| 吴江市| 达州市| 泸州市| 手机| 南昌市| 平潭县| 新蔡县| 枝江市| 双柏县| 凌云县| 加查县| 阜康市| 三原县| 宁晋县| 连云港市| 东乡| 禄丰县| 乌兰察布市| 山阴县| 丹凤县| 绵阳市| 永新县| 定远县| 洛川县| 澄江县|