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

Spring中的Actuator使用詳解

 更新時(shí)間:2023年09月12日 09:26:45   作者:墨城之左  
這篇文章主要介紹了Spring中的Actuator使用詳解,在生產(chǎn)環(huán)境中運(yùn)行的程序,并不總是穩(wěn)定、安靜、正確的,往往會(huì)遇到各式各樣的現(xiàn)場(chǎng)狀況,這個(gè)時(shí)候,就需要獲取該程序足夠多的運(yùn)行狀態(tài)信息,然后分析并對(duì)其進(jìn)行有效管理,需要的朋友可以參考下

1 Spring Actuator

在生產(chǎn)環(huán)境中運(yùn)行的程序,并不總是穩(wěn)定、安靜、正確的,往往會(huì)遇到各式各樣的現(xiàn)場(chǎng)狀況,這個(gè)時(shí)候,就需要獲取該程序足夠多的運(yùn)行狀態(tài)信息,然后分析并對(duì)其進(jìn)行有效管理。

Spring Boot Actuator 提供了多種特性來監(jiān)控和管理應(yīng)用程序,可以基于 HTTP,也可以基于 JMX。

將 actuator 依賴包添加到項(xiàng)目中

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

2 Endpoints

endpoint 可以理解為被管理(或被監(jiān)控) 對(duì)象 ,actuator 就是通過這些 endpoint 來實(shí)現(xiàn)對(duì)應(yīng)用程序的監(jiān)控管理。

spring 提供了大量的內(nèi)置 endpoint,比如 health,beans,mappings,endpoint 名稱也稱為 endpoint id:

ID描述默認(rèn)開啟JMXWEB
auditeventsExposes audit events information for the current application.YesYesNo
beansDisplays a complete list of all the Spring beans in your application.YesYesNo
cachesExposes available caches.YesYesNo
conditionsShows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match.YesYesNo
configpropsDisplays a collated list of all @ConfigurationProperties.YesYesNo
envExposes properties from Spring’s ConfigurableEnvironment.YesYesNo
flywayShows any Flyway database migrations that have been applied.YesYesNo
healthShows application health information.YesYesYes
httptraceDisplays HTTP trace information (by default, the last 100 HTTP request-response exchanges).YesYesNo
infoDisplays arbitrary application info.YesYesYes
integrationgraphShows the Spring Integration graph.YesYesNo
loggersShows and modifies the configuration of loggers in the application.YesYesNo
liquibaseShows any Liquibase database migrations that have been applied.YesYesNo
metricsShows ‘metrics’ information for the current application.YesYesNo
mappingsDisplays a collated list of all @RequestMapping paths.YesYesNo
scheduledtasksDisplays the scheduled tasks in your application.YesYesNo
sessionsAllows retrieval and deletion of user sessions from a Spring Session-backed session store. Not available when using Spring Session’s support for reactive web applications.YesYesNo
shutdownLets the application be gracefully shutdown.NoYesNo
threaddumpPerforms a thread dump.YesYesNo

對(duì)于 Web 應(yīng)用,還有以下 endpoint:

ID描述默認(rèn)開啟JMXWEB
heapdumpReturns a GZip compressed hprof heap dump file.YesN/ANo
jolokiaExposes JMX beans over HTTP (when Jolokia is on the classpath, not available for WebFlux).YesN/ANo
logfileReturns the contents of the logfile (if logging.file or logging.path properties have been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content.YesN/ANo
prometheusExposes metrics in a format that can be scraped by a Prometheus server.YesN/ANo

可以通過 endpoint id 來配置是否開啟該 endpoint,也可以通過 management.endpoints.enabled-by-default 屬性來配置改變是否默認(rèn)開啟的方式。

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

可以通過下面的屬性修改 JMX/Web 的默認(rèn)行為:

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

可以通過注解的方式來添加自定義的 Endpoint:

  • @Endpoint
  • @ReadOperation
  • @WriteOperatino
  • @DeleteOperation

例如:

@Endpoint(id = "hello")
@Service
public class HelloService{
   @ReadOperation
   public String hello(){
   	return "Hello Endpoint";
   }
}

然后通過 JConsole 可以看到新添加的 Endpoint Mbean:

在這里插入圖片描述

也可以通過以下 url 去訪問: /actuator/jolokia/exec/org.springframework.boot:type=Endpoint,name=Hello/hello

返回結(jié)果

{
    "request": {
        "mbean": "org.springframework.boot:type=Endpoint,name=Hello",
        "type": "exec",
        "operation": "hello"
    },
    "value": "Hello Endpoint",
    "timestamp": "xxxx",
    "status": 200    
}

有關(guān)于 MBean 的詳細(xì)信息的格式,可以通過 JConsole 查看,例如:

在這里插入圖片描述

3 Jolokia

使用 Jolokia 可以通過 HTTP 的形式來訪問 JMX Beans。

<dependency>
	<groupId>org.jolokia</groupId>
	<artifactId>jolokia-core</artifactId>
</dependency>

通過屬性 management.endpoints.web.exposure.include=* 來將 /actuator/jolokia 添加到 Web Mappings 中。

4 Health

Spring Actuator 默認(rèn)添加了以下 HealthIndicator:

  • CassandraHealthIndicator
  • CouchbaseHealthIndicator
  • DiskSpaceHealthIndicator
  • DataSourceHealthIndicator
  • ElasticsearchHealthIndicator
  • InfluxDbHealthIndicator
  • JmsHealthIndicator
  • MailHealthIndicator
  • MongoHealthIndicator
  • Neo4jHealthIndicator
  • RabbitHealthIndicator
  • RedisHealthIndicator
  • SolrHealthIndicator

比如,當(dāng) Spring 容易中有 InfluxDB bean 時(shí),Spring Actuator 就會(huì)自動(dòng)添加對(duì) InfluxDB health 的檢測(cè)。

@Bean
public InfluxDB getInfluxDB(){
	InfluxDB db = InfluxDBFatory.connect("http://localhost:8086", "root", "root");
	db.setDatabase("mydb");
	return db;
}

會(huì)看到:

在這里插入圖片描述

自定義 HealthIndicator 也非常的方便,比如:

@Component
public class MyHealthIndicator implements HealthIndicator {
	@Override
	public Health health() {
		int errorCode = check(); // perform some specific health check
		if (errorCode != 0) {
			return Health.down().withDetail("Error Code", errorCode).build();
		}
		return Health.up().build();
	}
}

5 Metric

Spring Boot Actuator 為 Micrometer 提供依賴管理和自動(dòng)配置,Micrometer 作用應(yīng)用程序指標(biāo)的 facade,可以支持各種類型的監(jiān)控系統(tǒng),包括:

AppOptics, Atlas, Datadog, Dynatrace, Elastic, Ganglia, Humio, Influx, JMX, KairosDB, New Relic, Prometheus, SignalFx, Simple(in-memory), StatsD, Wavefront.

基本概念:

  • Meter,MeterRegistry,Metric
  • Meter Type: Timer,Counter,Gauge,DistributionSummary,LongTaskTimer,F(xiàn)unctionCounter,F(xiàn)untionTimer,TImeGauge
  • Tag

下面,將應(yīng)用的指標(biāo)信息都輸出到 InfluxDB 數(shù)據(jù)庫中,需要做以下配置:

在配置文件中,添加 micrometer-registry-influx 依賴包

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-influx</artifactId>
</dependency>

然后再添加 InfluxmeterRegistry Bean 實(shí)例:

@Bean
public InfluxMeterRegistry getMeterRegistry(@Autowired InfluxConfig config){
	return new InfluxMeterRegistry(config, Clock.SYSTEM);
}

然后會(huì)在本地 InfluxDB 中看到以下 measurements:

在這里插入圖片描述

Spring Boot 默認(rèn)注冊(cè)的指標(biāo)以下幾類:

  • JVM metrics
  • CPU metrics
  • File descriptor metrics
  • Kafka consumer metrics
  • Logback/Log4j2 metrics
  • Uptime metrics
  • Tomcat metrics
  • Spring Integration metrics

到此這篇關(guān)于Spring中的Actuator使用詳解的文章就介紹到這了,更多相關(guān)Spring中的Actuator內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java實(shí)現(xiàn)操作系統(tǒng)中的最佳置換Optimal算法

    java實(shí)現(xiàn)操作系統(tǒng)中的最佳置換Optimal算法

    這篇文章主要介紹了java實(shí)現(xiàn)操作系統(tǒng)中的最佳置換Optimal算法 ,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • spring如何集成cxf實(shí)現(xiàn)webservice接口功能詳解

    spring如何集成cxf實(shí)現(xiàn)webservice接口功能詳解

    這篇文章主要給大家介紹了關(guān)于spring如何集成cxf實(shí)現(xiàn)webservice接口功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家 的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧
    2018-07-07
  • 淺談java 執(zhí)行jar包中的main方法

    淺談java 執(zhí)行jar包中的main方法

    下面小編就為大家?guī)硪黄獪\談java 執(zhí)行jar包中的main方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-09-09
  • mybatis sum(參數(shù)) 列名作為參數(shù)的問題

    mybatis sum(參數(shù)) 列名作為參數(shù)的問題

    這篇文章主要介紹了mybatis sum(參數(shù)) 列名作為參數(shù)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • 詳解SpringBoot中5種類型參數(shù)傳遞和json數(shù)據(jù)傳參的操作

    詳解SpringBoot中5種類型參數(shù)傳遞和json數(shù)據(jù)傳參的操作

    當(dāng)涉及到參數(shù)傳遞時(shí),Spring?Boot遵循HTTP協(xié)議,并支持多種參數(shù)傳遞方式,這些參數(shù)傳遞方式可以根據(jù)請(qǐng)求的不同部分進(jìn)行分類,
    2023-12-12
  • springboot3?redis?常用操作工具類詳解

    springboot3?redis?常用操作工具類詳解

    本文詳細(xì)介紹了Spring Boot 3中使用Spring Data Redis進(jìn)行Redis操作的工具類實(shí)現(xiàn),該工具類涵蓋了字符串、哈希、列表、集合和有序集合等常用功能,感興趣的朋友一起看看吧
    2025-01-01
  • Spring如何將bean添加到容器中

    Spring如何將bean添加到容器中

    這篇文章主要介紹了Spring如何將bean添加到容器中,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-05-05
  • Spring切入點(diǎn)表達(dá)式配置過程圖解

    Spring切入點(diǎn)表達(dá)式配置過程圖解

    這篇文章主要介紹了Spring切入點(diǎn)表達(dá)式配置過程圖解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Integer IntegerCache源碼閱讀

    Integer IntegerCache源碼閱讀

    這篇文章主要介紹了Integer IntegerCache源碼閱讀,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-01-01
  • Java Socket實(shí)現(xiàn)文件傳輸示例代碼

    Java Socket實(shí)現(xiàn)文件傳輸示例代碼

    這篇文章主要介紹了Java Socket實(shí)現(xiàn)文件傳輸示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01

最新評(píng)論

东台市| 凯里市| 平和县| 嘉祥县| 大关县| 北票市| 新安县| 济阳县| 大埔县| 德昌县| 巴南区| 大关县| 澄江县| 墨竹工卡县| 洛宁县| 清丰县| 神农架林区| 吴桥县| 丰镇市| 苏尼特右旗| 康乐县| 平南县| 雷州市| 张家界市| 青浦区| 萍乡市| 耒阳市| 宣城市| 东源县| 收藏| 汝城县| 莒南县| 兴和县| 江门市| 本溪| 比如县| 南木林县| 泉州市| 乌鲁木齐县| 类乌齐县| 苍南县|