? ? ? ? ? ? ? ? ? ? ? ?
docker實(shí)戰(zhàn)(一):centos7 yum安裝docker
docker實(shí)戰(zhàn)(二):基礎(chǔ)命令篇
docker實(shí)戰(zhàn)(三):docker網(wǎng)絡(luò)模式(超詳細(xì))
docker實(shí)戰(zhàn)(四):docker架構(gòu)原理
docker實(shí)戰(zhàn)(五):docker鏡像及倉庫配置
docker實(shí)戰(zhàn)(六):docker 網(wǎng)絡(luò)及數(shù)據(jù)卷設(shè)置
docker實(shí)戰(zhàn)(七):docker 性質(zhì)及版本選擇
認(rèn)知升維: 道、法、術(shù)、器、勢
?
spring boot actuator介紹
-
Spring Boot包含許多其他功能,可幫助您在將應(yīng)用程序推送到生產(chǎn)環(huán)境時(shí)監(jiān)視和管理應(yīng)用程序。
-
您可以選擇使用HTTP端點(diǎn)或JMX來管理和監(jiān)視應(yīng)用程序。
-
審核,運(yùn)行狀況和指標(biāo)收集也可以自動(dòng)應(yīng)用于您的應(yīng)用程序。
總之Spring Boot Actuator就是一款可以幫助你監(jiān)控系統(tǒng)數(shù)據(jù)的框架,其可以監(jiān)控很多很多的系統(tǒng)數(shù)據(jù),它有對(duì)應(yīng)用系統(tǒng)的自省和監(jiān)控的集成功能,可以查看應(yīng)用配置的詳細(xì)信息,如:
顯示應(yīng)用程序員的Health健康信息顯示Info應(yīng)用信息
顯示HTTP Request跟蹤信息
顯示當(dāng)前應(yīng)用程序的“Metrics”信息
顯示所有的@RequestMapping的路徑信息
顯示應(yīng)用程序的各種配置信息
顯示你的程序請(qǐng)求的次數(shù) 時(shí)間 等各種信息
引入Actuactor三角坐標(biāo)依賴?
<!-- 端點(diǎn)監(jiān)控的配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
訪問:?http://localhost:9999/actuator/? ? ? ? ?響應(yīng)信息如下所示
{
?? ?"_links": {
?? ??? ?"self": {
?? ??? ??? ?"href": "http://localhost:9999/actuator",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"beans": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/beans",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"caches-cache": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/caches/{cache}",
?? ??? ??? ?"templated": true
?? ??? ?},
?? ??? ?"caches": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/caches",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"health": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/health",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"health-path": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/health/{*path}",
?? ??? ??? ?"templated": true
?? ??? ?},
?? ??? ?"info": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/info",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"conditions": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/conditions",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"configprops": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/configprops",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"configprops-prefix": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/configprops/{prefix}",
?? ??? ??? ?"templated": true
?? ??? ?},
?? ??? ?"env": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/env",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"env-toMatch": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/env/{toMatch}",
?? ??? ??? ?"templated": true
?? ??? ?},
?? ??? ?"loggers": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/loggers",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"loggers-name": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/loggers/{name}",
?? ??? ??? ?"templated": true
?? ??? ?},
?? ??? ?"heapdump": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/heapdump",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"threaddump": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/threaddump",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"metrics-requiredMetricName": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/metrics/{requiredMetricName}",
?? ??? ??? ?"templated": true
?? ??? ?},
?? ??? ?"metrics": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/metrics",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"scheduledtasks": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/scheduledtasks",
?? ??? ??? ?"templated": false
?? ??? ?},
?? ??? ?"mappings": {
?? ??? ??? ?"href": "http://localhost:9999/actuator/mappings",
?? ??? ??? ?"templated": false
?? ??? ?}
?? ?}
}?
訪問health端點(diǎn):?http://localhost:9999/actuator/health? 響應(yīng)信息如下:
{
?? ?"status": "UP",
?? ?"components": {
?? ??? ?"diskSpace": {
?? ??? ??? ?"status": "UP",
?? ??? ??? ?"details": {
?? ??? ??? ??? ?"total": 1333606182912,
?? ??? ??? ??? ?"free": 1269725843456,
?? ??? ??? ??? ?"threshold": 10485760,
?? ??? ??? ??? ?"exists": true
?? ??? ??? ?}
?? ??? ?},
?? ??? ?"elasticsearch": {
?? ??? ??? ?"status": "UP",
?? ??? ??? ?"details": {
?? ??? ??? ??? ?"cluster_name": "elasticsearch",
?? ??? ??? ??? ?"status": "green",
?? ??? ??? ??? ?"timed_out": false,
?? ??? ??? ??? ?"number_of_nodes": 1,
?? ??? ??? ??? ?"number_of_data_nodes": 1,
?? ??? ??? ??? ?"active_primary_shards": 0,
?? ??? ??? ??? ?"active_shards": 0,
?? ??? ??? ??? ?"relocating_shards": 0,
?? ??? ??? ??? ?"initializing_shards": 0,
?? ??? ??? ??? ?"unassigned_shards": 0,
?? ??? ??? ??? ?"delayed_unassigned_shards": 0,
?? ??? ??? ??? ?"number_of_pending_tasks": 0,
?? ??? ??? ??? ?"number_of_in_flight_fetch": 0,
?? ??? ??? ??? ?"task_max_waiting_in_queue_millis": 0,
?? ??? ??? ??? ?"active_shards_percent_as_number": 100.0
?? ??? ??? ?}
?? ??? ?},
?? ??? ?"ping": {
?? ??? ??? ?"status": "UP"
?? ??? ?},
?? ??? ?"r2dbc": {
?? ??? ??? ?"status": "UP",
?? ??? ??? ?"details": {
?? ??? ??? ??? ?"database": "Jasync-MySQL",
?? ??? ??? ??? ?"validationQuery": "validate(REMOTE)"
?? ??? ??? ?}
?? ??? ?}
?? ?}
}
開啟 Info端點(diǎn):? yml文件中配置:?
# 顯示任意的應(yīng)用信息,默認(rèn)關(guān)閉 springBoot版本:2.7.5 CURRENT GA如果是更低一些的版本默認(rèn)是開啟的
# 在spring boot 2.0以后,actuator默認(rèn)只開啟了info和health兩個(gè)端點(diǎn),要想使用其他的端點(diǎn),需要在application.yml中打開 management: endpoint: health: show-details: always # 配置health端點(diǎn)顯示詳細(xì)信息 info: env: enabled: true # 顯示任意的應(yīng)用信息,默認(rèn)關(guān)閉 springBoot版本:2.7.5 CURRENT GA如果是更低一些的版本默認(rèn)是開啟的 endpoints: web: exposure: include: "*" cors: allowed-headers: "*" info: app: encoding: @project.build.sourceEncoding@ java: source: @java.version@ target: @java.version@
訪問info端點(diǎn):?http://localhost:9999/actuator/info? ?響應(yīng)信息如下:
{
?? ?"app": {
?? ??? ?"encoding": "UTF-8",
?? ??? ?"java": {
?? ??? ??? ?"source": "1.8.0_221",
?? ??? ??? ?"target": "1.8.0_221"
?? ??? ?}
?? ?}
}
拓展info端點(diǎn):
package org.jd.websocket.auth.data.reactor.help; import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.InfoContributor; import org.springframework.stereotype.Component; import java.util.Collections; import java.util.Date; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @Component public class CustomBuildInfoContributor implements InfoContributor { @Override public void contribute(Info.Builder builder) { Map<String,Object> details= new ConcurrentHashMap<>(); details.put("build",Collections.singletonMap("timestamp",new Date())); details.put("author","YangGe"); builder.withDetails(details); } }
再次訪問info端點(diǎn):?http://localhost:9999/actuator/info? ?響應(yīng)信息如下:?
{
?? ?"app": {
?? ??? ?"encoding": "UTF-8",
?? ??? ?"java": {
?? ??? ??? ?"source": "1.8.0_221",
?? ??? ??? ?"target": "1.8.0_221"
?? ??? ?}
?? ?},
?? ?"build": {
?? ??? ?"timestamp": "2023-08-07T15:14:28.463+00:00"
?? ?},
?? ?"author": "YangGe"
}
management:
? endpoints:
? ? web:
? ? ? base-path: /actuator ?#配置端點(diǎn)訪問前綴
? ? ? exposure:
? ? ? ? include: info,health ?#只暴露info,health兩個(gè)端點(diǎn); “*” 表示暴露所有端點(diǎn)
? ? ? ? exclude: health ?#可以將以暴露的端點(diǎn)排除(不暴露)
?
其他更細(xì)節(jié)的配置可以看官網(wǎng)
spring boot?熱部署導(dǎo)入devtool依賴idea窗口鈍化
yml yet anothor markup language
actuator是spring boot 提供的對(duì)應(yīng)系統(tǒng)的自省和監(jiān)控的基礎(chǔ)功能,當(dāng)出現(xiàn)問題時(shí)可以及時(shí)的定位問題。
拓展Metrics端點(diǎn):
http://localhost:9999/actuator/metrics? ?訪問該端點(diǎn),響應(yīng)信息如下
{
????"names":[
????????"application.ready.time",
????????"application.started.time",
????????"disk.free",
????????"disk.total",
????????"executor.active",
????????"executor.completed",
????????"executor.pool.core",
????????"executor.pool.max",
????????"executor.pool.size",
????????"executor.queue.remaining",
????????"executor.queued",
????????"http.server.requests",
????????"jvm.buffer.count",
????????"jvm.buffer.memory.used",
????????"jvm.buffer.total.capacity",
????????"jvm.classes.loaded",
????????"jvm.classes.unloaded",
????????"jvm.gc.live.data.size",
????????"jvm.gc.max.data.size",
????????"jvm.gc.memory.allocated",
????????"jvm.gc.memory.promoted",
????????"jvm.gc.overhead",
????????"jvm.gc.pause",
????????"jvm.memory.committed",
????????"jvm.memory.max",
????????"jvm.memory.usage.after.gc",
????????"jvm.memory.used",
????????"jvm.threads.daemon",
????????"jvm.threads.live",
????????"jvm.threads.peak",
????????"jvm.threads.states",
????????"logback.events",
????????"process.cpu.usage",
????????"process.start.time",
????????"process.uptime",
????????"system.cpu.count",
????????"system.cpu.usage"
????]
}對(duì)應(yīng)這些端點(diǎn)信息,用于實(shí)現(xiàn)生產(chǎn)級(jí)的度量工具. 這些指標(biāo)包括內(nèi)存總量,空閑內(nèi)存數(shù)據(jù),處理器數(shù)量,系統(tǒng)正常運(yùn)行時(shí)間,堆信息等,如果想了解某項(xiàng)指標(biāo)的信息,
http://localhost:9999/actuator/metrics
端點(diǎn)后加上上述指標(biāo)的名稱即可。如當(dāng)前內(nèi)存使用情況可以通過:
http://localhost:9999/actuator/metrics/jvm.memory.used? 就會(huì)得到如下響應(yīng)信息:
{
????"name":"jvm.memory.used",
????"description":"The amount of used memory",
????"baseUnit":"bytes",
????"measurements":[
????????{
????????????"statistic":"VALUE",
????????????"value":479145136
????????}
????],
????"availableTags":[
????????{
????????????"tag":"area",
????????????"values":[
????????????????"heap",
????????????????"nonheap"
????????????]
????????},
????????{
????????????"tag":"id",
????????????"values":[
????????????????"Compressed Class Space",
????????????????"PS Survivor Space",
????????????????"PS Old Gen",
????????????????"Metaspace",
????????????????"PS Eden Space",
????????????????"Code Cache"
????????????]
????????}
????]
}
http://localhost:9999/actuator/metrics/jvm.memory.usage.after.gc? gc回收內(nèi)存的情況文章來源:http://www.zghlxwxcb.cn/news/detail-631885.html
{
????"name":"jvm.memory.usage.after.gc",
????"description":"The percentage of long-lived heap pool used after the last GC event, in the range [0..1]",
????"baseUnit":"percent",
????"measurements":[
????????{
????????????"statistic":"VALUE",
????????????"value":0.0014572154044711605
????????}
????],
????"availableTags":[
????????{
????????????"tag":"area",
????????????"values":[
????????????????"heap"
????????????]
????????},
????????{
????????????"tag":"pool",
????????????"values":[
????????????????"long-lived"
????????????]
????????}
????]
}文章來源地址http://www.zghlxwxcb.cn/news/detail-631885.html
到了這里,關(guān)于Spring Boot2.xx開啟監(jiān)控 Actuator的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!