欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

使用SpringBoot很久了,但是很少使用到SpringBoot的查看和監(jiān)控,將來八成也不會用到,萬一有機會用到呢?

所以記錄一下以前學(xué)習(xí)SpringBoot+actuator和adminUI實現(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)入對應(yīng)的包

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

<!-- security 一旦導(dǎo)入就會生效 -->
<!--
<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

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

# actuator 信息
info.actuator.name=test

啟動之后

myw

訪問

http://localhost:8081/sys/actuator

myw

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

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

缺點:沒有可視化界面

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

應(yī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)用程序運行狀況信息 up表示成功 down失敗,對于懶加載沒報錯的可以看到控制臺報錯了
  • /actuator/info 查看自定義應(yīng)用信息

懶加載有個缺點,例如mysql的配置,啟動的時候不會發(fā)現(xiàn)錯誤,只有運行的時候才報錯

當(dāng)訪問

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
# 默認 never always可以顯示硬盤使用情況和線程情況
management.endpoint.health.show-details=always
# 端點暴露的內(nèi)容,默認["health","info"],設(shè)置"*"代表暴露所有可訪問的端點
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客戶端通過instances注冊,見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(); // 所有請求必須通過認證

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

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

啟動客戶端和服務(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é)

備注記錄到這里 將來會不會用到再說了。

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

相關(guān)文章

  • Java Web監(jiān)聽器如何實現(xiàn)定時發(fā)送郵件

    Java Web監(jiān)聽器如何實現(xiàn)定時發(fā)送郵件

    這篇文章主要介紹了Java Web監(jiān)聽器如何實現(xiàn)定時發(fā)送郵件,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-12-12
  • 基于java高并發(fā)處理方案

    基于java高并發(fā)處理方案

    這篇文章主要介紹了基于java高并發(fā)處理方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • Java綜合整理堆排序?快速排序?歸并排序

    Java綜合整理堆排序?快速排序?歸并排序

    堆排序是利用堆這種數(shù)據(jù)結(jié)構(gòu)而設(shè)計的一種排序算法,堆排序是一種選擇排序,它的最壞,最好,平均時間復(fù)雜度均為O(nlogn),它也是不穩(wěn)定排序。首先簡單了解下堆結(jié)構(gòu)
    2022-01-01
  • Spring Boot環(huán)境屬性占位符解析及類型轉(zhuǎn)換詳解

    Spring Boot環(huán)境屬性占位符解析及類型轉(zhuǎn)換詳解

    這篇文章主要給大家介紹了關(guān)于Spring Boot環(huán)境屬性占位符解析及類型轉(zhuǎn)換的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-08-08
  • Java多線程用法的實例詳解

    Java多線程用法的實例詳解

    這篇文章主要介紹了Java多線程用法的實例詳解的相關(guān)資料,希望通過本文大家能夠理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-09-09
  • 普通對象使用spring容器中的對象的實現(xiàn)方法

    普通對象使用spring容器中的對象的實現(xiàn)方法

    這篇文章主要介紹了普通對象使用spring容器中的對象的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Java中的線程安全集合CopyOnWriteArrayList解析

    Java中的線程安全集合CopyOnWriteArrayList解析

    這篇文章主要介紹了Java中的線程安全CopyOnWriteArrayList解析,CopyOnWriteArrayList是ArrayList的線程安全版本,從他的名字可以推測,CopyOnWriteArrayList是在有寫操作的時候會copy一份數(shù)據(jù),然后寫完再設(shè)置成新的數(shù)據(jù),需要的朋友可以參考下
    2023-12-12
  • Java中使用jaxp進行sax解析_動力節(jié)點Java學(xué)院整理

    Java中使用jaxp進行sax解析_動力節(jié)點Java學(xué)院整理

    使用SAX的優(yōu)勢在于其解析速度較快,相對于DOM而言占用內(nèi)存較少。這篇文章主要介紹了Java中使用jaxp進行sax解析,需要的朋友可以參考下
    2017-08-08
  • Java?常見排序算法代碼分享

    Java?常見排序算法代碼分享

    這篇文章主要介紹了Java?常見排序算法代碼分享,文章通過分享詳細的代碼總結(jié)文章內(nèi)容,具有一定的參考價值,需要的小伙伴可以參考一下,希望對你有所幫助
    2022-03-03
  • Java拆裝箱深度剖析

    Java拆裝箱深度剖析

    這篇文章主要為大家深度剖析了Java拆箱裝箱的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12

最新評論