日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
如何做好對SpringBoot項目全面監(jiān)控之Actuator

定義

Actuator 為springboot項目提供了很全面的監(jiān)控和審查,通過啟用和公開endpoints,可以很方便的查看項目中的一些指標(biāo)。

專注于為中小企業(yè)提供網(wǎng)站設(shè)計制作、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)淅川免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了近1000家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

添加依賴



org.springframework.boot
spring-boot-starter-actuator

關(guān)于Endpoints

Actuator提供了很多內(nèi)置的Endpoints,每一個EP都可以啟用/禁用 和 公開。

當(dāng)然,EP只有啟動并公開之后,才會真正生效。

如何啟用/禁用Endpoints?

除了 shutdown 之外,所有的EP都是默認(rèn)啟用的,如果要啟用/禁用EP,可使用以下配置:

management.endpoint..enabled=true/false?。

比如啟用 shutdown :

management.endpoint.shutdown.enabled=true

為了安全,在生產(chǎn)環(huán)境不建議啟用所有的EP,而是按需啟用,所以要首先禁用默認(rèn)行為,然后啟用需要的EP,如下:

management.endpoints.enabled-by-default=false
management.endpoint.info.enabled=true

這樣只有啟用的EP才會加載到上下文。

這樣只是啟用和禁用了EP,但是否暴露出去,還需要單獨的配置。

如何暴露/隱藏 Endpoints?

EP會暴露應(yīng)用的很多指標(biāo),所以非常重要和敏感,在生產(chǎn)環(huán)境一定要做好選擇和安全防護(hù)。

暴露和隱藏使用以下配置:

# 針對 JMX 規(guī)范協(xié)議
management.endpoints.jmx.exposure.exclude
management.endpoints.jmx.exposure.include *
# 針對http協(xié)議
management.endpoints.web.exposure.exclude
management.endpoints.web.exposure.include health

使用 include 暴露Ep,使用 exclude 隱藏 Ep,其中 exclude 優(yōu)先級高于 include。

星號 * 表示全部的,另外星號在properties和yaml中有一點不同:

在YAML中星號(*)具有特殊的含義,所以需要用雙引號括起來,如 "*"

比如要隱藏所有的并僅僅啟用health和info:

management.endpoints.web.exposure.include=health,info

比如要暴露所有并禁用env和beans:

management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans

前文有述,EP包括很多敏感信息,一定要注意安全,那應(yīng)該如何確保安全?

如何實現(xiàn)Http Endpoints 安全加固

如果項目中使用了 spring security 或 shiro 等安全框架,可以把EP放在安全框架之后,和其他業(yè)務(wù)API一樣保護(hù)起來。

或者,也可以使用RequestMatcher對象來配合使用,以控制某些用戶具備訪問權(quán)限,比如:

import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration(proxyBeanMethods = false)
public class MySecurityConfiguration {

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.requestMatcher(EndpointRequest.toAnyEndpoint())
.authorizeRequests((requests) -> requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
http.httpBasic();
return http.build();
}
}

這樣只有具備 ENDPOINT_ADMIN 角色的用戶才可以訪問EP。

如何通過頁面訪問各類指標(biāo)

通過項目的 ip:port /actuator ,比如 localhost:8080/actuator:

可以通過配置修改路徑:

# 修改 /actutor 為 /manage
management.endpoints.web.base-path=/manage

# 修改特定指標(biāo) /health 為 /myhealth
management.endpoints.web.path-mapping.health=myhealth

# 修改訪問端口(默認(rèn)和server.port相同)
management.server.port=8036

當(dāng)前題目:如何做好對SpringBoot項目全面監(jiān)控之Actuator
分享地址:http://www.5511xx.com/article/dhsjcse.html