SpringBoot Starter Actuator

SpringBoot Actuator是的子項目Spring Boot框架。它包括許多其他功能,可幫助我們監(jiān)視和管理Spring Boot應(yīng)用程序。它包含 Actuator端點(資源所在的位置)。我們可以使用 HTTP JMX 端點來管理和監(jiān)視Spring Boot應(yīng)用程序。如果要在應(yīng)用程序中獲得生產(chǎn)就緒的功能,則應(yīng)使用S pring Boot Actuator。

Spring Boot Actuator功能

Spring Boot Actuator有 三個主要功能:

Endpoints Metrics Audit

Endpoint: Actuator端點使我們可以監(jiān)視應(yīng)用程序并與之交互。 Spring Boot提供了許多內(nèi)置端點。我們也可以創(chuàng)建自己的端點。我們可以分別啟用和禁用每個端點。大多數(shù)應(yīng)用程序選擇 HTTP ,該終結(jié)點的ID和 /actuator前綴映射到URL。

對于例如, /health 端點提供了應(yīng)用程序的基本健康信息。 Actuator默認(rèn)情況下將其映射到 /actuator/health 。

Metrics: Spring Boot Actuator通過與 千分尺集成來提供尺寸指標(biāo)。千分尺已集成到Spring Boot中。它是工具庫,用于支持從Spring交付應(yīng)用程序指標(biāo)。它為具有維度數(shù)據(jù)模型的 計時器,儀表,計數(shù)器,分配匯總長任務(wù)計時器提供了與供應(yīng)商無關(guān)的界面。

Audit: Spring Boot提供了一個靈活的審核框架,該框架將事件發(fā)布到 AuditEventRepository。如果正在執(zhí)行spring-security,它將自動發(fā)布身份驗證事件。

啟用Spring Boot Actuator

我們可以通過在pom.xml文件中注入依賴項 spring-boot-starter-actuator 來啟用 Actuator。

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

Spring Boot Actuator端點

Actuator端點允許我們監(jiān)視Spring Boot應(yīng)用程序并與之交互。 Spring Boot包含許多內(nèi)置端點,我們還可以在Spring Boot應(yīng)用程序中添加自定義端點。

下表描述了廣泛使用的端點。

Id 用法默認(rèn)
Actuator它為其他端點提供了一個基于超媒體的發(fā)現(xiàn)頁面。它要求Spring HATEOAS位于類路徑上。true
auditevents它公開了當(dāng)前應(yīng)用程序的審核事件信息。true
autoconfig它用于顯示自動配置報告,該報告顯示所有自動配置候選者以及應(yīng)用它們"被"或"未被"的原因。true
beans它用于顯示應(yīng)用程序中所有Spring Bean的完整列表。true
configprops它用于顯示所有@ConfigurationProperties的整理列表。true
dump它用于執(zhí)行線程轉(zhuǎn)儲。true
env它用于從Spring的ConfigurableEnvironment中公開屬性。true
flyway它用于顯示已應(yīng)用的所有Flyway數(shù)據(jù)庫遷移。true
health它用于顯示應(yīng)用程序運行狀況信息。錯誤
info它用于顯示任意應(yīng)用程序信息。錯誤
loggers它用于顯示和修改應(yīng)用程序中記錄器的配置。true
liquibase它用于顯示已應(yīng)用的所有Liquibase數(shù)據(jù)庫遷移。true
metrics它用于顯示當(dāng)前應(yīng)用程序的指標(biāo)信息。true
mappings它用于顯示所有@RequestMapping路徑的整理列表。true
shutdown它用于允許正常關(guān)閉應(yīng)用程序。true
trace它用于顯示跟蹤信息。true

對于Spring MVC,使用了以下附加端點。

Id說明默認(rèn)
docs它用于顯示文檔,包括對 Actuator端點的示例請求和響應(yīng)。錯誤
heapdump它用于返回GZip壓縮的hprof堆轉(zhuǎn)儲文件。true
jolokia它用于通過HTTP公開JMX bean(當(dāng)Jolokia在類路徑上時)。true
logfile它用于返回日志文件的內(nèi)容。true
prometheus它用于以Prometheus服務(wù)器可以抓取的格式公開指標(biāo)。它需要依賴千分尺-普羅米修斯。true

Spring Boot Actuator屬性

Spring Boot為所有 Actuator端點提供安全性。它使用 基于表單的身份驗證,該身份提供 用戶ID 作為用戶,并提供隨機(jī)生成的 密碼。我們還可以通過為端點定制基本身份驗證安全性來訪問 Actuator受限的端點。我們需要通過 management.security.roles 屬性覆蓋此配置。例如:

management.security.enabled=true
management.security.roles=ADMIN
security.basic.enabled=true
security.user.name=admin
security.user.passowrd=admin

彈簧啟動 Actuator示例

讓我們通過示例了解 Actuator的概念。

步驟1: 打開彈簧Initializr https://start.spring.io/并創(chuàng)建 Maven 項目。

步驟2: 提供 名稱。我們提供了 com.nhooo。

步驟3: 提供 工件 ID。我們提供了 spring-boot-actuator-example。

步驟4: 。添加以下依賴項: Spring Web,Spring Boot Starter Actuator Spring Data Rest HAL瀏覽器。

步驟5: 單擊 生成按鈕。當(dāng)我們單擊"生成"按鈕時,它將與項目相關(guān)的所有規(guī)范包裝到 Jar 文件中,并將其下載到我們的本地系統(tǒng)中。

Spring Boot Starter Actuator

步驟6: 提取Jar文件并將其粘貼到STS工作區(qū)中。

步驟7: 導(dǎo)入項目文件夾。

文件->導(dǎo)入->現(xiàn)有Maven項目->瀏覽->選擇文件夾spring-boot-actuator-example- >完成

導(dǎo)入需要一些時間。導(dǎo)入項目后,我們可以在"包資源管理器"部分中看到項目目錄。

Spring Boot Starter Actuator

步驟8: : 創(chuàng)建一個Controller類。我們已經(jīng)創(chuàng)建了名為DemoRestController的控制器類。

DemoRestController.java

package com.nhooo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DemoRestController 
{
@GetMapping("/hello")
public String hello() 
{
return "Hello User!";
}
}

步驟9: 打開 application.properties 文件,并通過添加以下語句來禁用 Actuator的安全性功能。

application.properties

management.security.enabled=false

步驟10: 運行 SpringBootActuatorExampleApplication.java 文件。

步驟11: 打開瀏覽器并調(diào)用URL http: //localhost: 8080/actuator。它返回以下頁面:

{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"health":{"href":"http://localhost:8080/actuator/health","templated":false},"health-path":{"href":"http://localhost:8080/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:8080/actuator/info","templated":false}}}

默認(rèn)情況下,該應(yīng)用程序在端口8080上運行。 Actuator啟動后,我們可以看到通過HTTP公開的所有端點的列表。

讓我們通過調(diào)用URL http: //localhost: 8080/來調(diào)用 health 端點。 Actuator/健康狀況。它表示狀態(tài) UP 。這表示該應(yīng)用程序運行正常,并且運行正常。

Spring Boot Starter Actuator

同樣,我們可以調(diào)用其他端點來幫助我們監(jiān)視和管理Spring Boot應(yīng)用程序。


丰满人妻一级特黄a大片,午夜无码免费福利一级,欧美亚洲精品在线,国产婷婷成人久久Av免费高清