成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Spring Boot默認的指標數(shù)據(jù)從哪來的?

開發(fā) 后端
您是否注意到 Spring Boot 和 Micrometer 為您的應用生成的所有默認指標?如果沒有 - 您可以將 actuator 依賴項添加到項目中,然后點擊 / actuator / metrics 端點,在那里您將找到有關(guān) JVM 、進程、Tomcat、流量等的有用信息。

您是否注意到 Spring Boot 和 Micrometer 為您的應用生成的所有默認指標?如果沒有 - 您可以將 actuator 依賴項添加到項目中,然后點擊 / actuator / metrics 端點,在那里您將找到有關(guān) JVM 、進程、Tomcat、流量等的有用信息。

然后,添加一些緩存,數(shù)據(jù)源 或 JPA 依賴項,甚至會出現(xiàn)更多指標。如果您想知道它們是如何結(jié)束的,我們可以在哪里找到關(guān)于它們所描述的參數(shù)的解釋,那么這篇文章就是為您準備的。

顯示指標

為了讓它井然有序,讓我們從如何在 Spring Boot 應用程序中顯示指標開始。如果您已經(jīng)知道了,可以跳過這一部分。

Spring Boot中的指標由 micrometer.io 處理。但是,如果您使用 actuator ,則不需要向項目添加 micrometer 依賴項,因為 actuator 已經(jīng)依賴于它。即使您對它提供的端點不感興趣,也希望您使用 actuator ,因為這是通過其 AutoConfigurations 注冊許多指標的模塊。稍后我們會詳細討論。

因此,首先,只需將執(zhí)行器依賴項添加到項目中(這里是 build.gradle.kts ) 

  1. dependencies {  
  2.     implementation("org.springframework.boot:spring-boot-starter-actuator")  

并在執(zhí)行器端點中顯示指標名稱,點擊 http://localhost:8080/actuator/metrics. 

  1.  
  2.   "names": [  
  3.     "jvm.threads.states",  
  4.     "process.files.max",  
  5.     "jvm.memory.used",  
  6.     "jvm.gc.memory.promoted",  
  7.     "jvm.memory.max", 
  8.      "system.load.average.1m",  
  9.     ...  
  10.   ]  

然后,要查看詳細信息,請在 URL 路徑中添加指標名稱,例如:http://localhost:8080/actuator/metrics/system.cpu.count. 

  1.  
  2.   "name": "system.cpu.count",  
  3.   "description": "The number of processors available to the Java virtual machine",  
  4.   "baseUnit": null,  
  5.   "measurements": [  
  6.     {  
  7.       "statistic": "VALUE",  
  8.       "value": 8 
  9.      }  
  10.   ],  
  11.   "availableTags": [  
  12.   ]  

通過提供特定的儀表注冊表,可以定期將這些指標發(fā)送到您選擇的指標系統(tǒng)( Prometheus,New Relic,CloudWatch,Graphite 等)。讓我們用最簡單的注冊表來做 - LoggingMeterRegistry,它只是定期記錄所有指標。 

  1. @Configuration  
  2. class MetricsConfig {  
  3.     @Bean  
  4.     LoggingMeterRegistry loggingMeterRegistry() {  
  5.         return new LoggingMeterRegistry();  
  6.     }  

現(xiàn)在,指標也顯示在日志中: 

  1. 2019-07-17 11:07:09.406  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.buffer.count{id=directvalue=0 buffers  
  2. 2019-07-17 11:07:09.406  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.buffer.count{id=mappedvalue=0 buffers  
  3. 2019-07-17 11:07:09.406  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.buffer.memory.used{id=directvalue=0 B  
  4. 2019-07-17 11:07:09.406  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.buffer.memory.used{id=mappedvalue=0 B  
  5. 2019-07-17 11:07:09.408  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.classes.loaded{} value=8530 classes  
  6. 2019-07-17 11:07:09.408  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.gc.live.data.size{} value=0 B  
  7. 2019-07-17 11:07:09.408  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.gc.max.data.size{} value=0 B 
  8. 2019-07-17 11:07:09.410  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.memory.committed{area=nonheap,id=Compressed Class Space} value=6.25 MiB 
  9. 2019-07-17 11:07:09.410  INFO 91283 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : jvm.memory.committed{area=heap,id=G1 Eden Space} value=168 MiB 
  10. ... 

指標供應

那么,如何提供這些指標呢?一個示例可能是 WebMvcMetricsFilter ,向所有 Spring Web MVC 端點添加性能指標 (http.server.requests metric) 。

但是這個例子很簡單。當所有請求都由 Spring 框架處理時,在內(nèi)部添加調(diào)用生成指標是沒有必要的(只檢查 WebMvcMetricsFilter.record() 方法)。

但是,如果您使用純 ehcache 或 hibernate 或其他數(shù)據(jù)源,然后生成指標,情況又會如何呢?

那么 cache. * 指標呢,即使我 @Autowired 純 net.sf.ehcache.Cache 也會生成?

那么 hibernate. * 指標呢,即使我 @Autowired 純 org.hibernate.SessionFactory 也會生成?

然后, jvm.* , process.* , tomcat.* 等如何自動生成?

它似乎比人們想象的更簡單,因為這些統(tǒng)計數(shù)據(jù)是由受監(jiān)控的組件本身提供的。有時,它將直接提供,例如cache.getStatistics() 為 EhCache 提供 StatisticsGateway *,*或 sessionFactory.getStatistics() 為 Hibernate SessionFactory 提供 statistics 等等。

有時,這可以通過其他方式實現(xiàn),比如托管 bean 。例如,將 RuntimeMXBean 用于 JVM process.* 指標以及 將(如GlobalRequestProcessor, Servlet 等) Tomcat mbeans 用于 tomcat. * 指標

為了訪問這些統(tǒng)計數(shù)據(jù)并將其轉(zhuǎn)換為特定指標,Micrometer 引入了 MeterBinder 的概念。

檢查 MeterBinder implementation 層次結(jié)構(gòu),您將了解更多關(guān)于可用的指標組的信息。

Micrometer MeterBinders

您也可以直接在 micrometer repo 上檢查。

打開,例如, EhCache2Metrics ,您將找到 Ehcache 統(tǒng)計信息映射到特定 Micrometer 指標的內(nèi)容和方式。 

  1. cache.size -> StatisticsGateway:getSize cache.gets{result=miss} -> StatisticsGateway:cacheMissCount cache.gets{result=hit} -> StatisticsGateway:cacheHitCount cache.puts -> StatisticsGateway:cachePutCount cache.evictions -> StatisticsGateway:cacheEvictedCount cache.remoteSize -> StatisticsGateway::getRemoteSize cache.removals -> StatisticsGateway::cacheRemoveCount cache.puts.added{result=added} -> StatisticsGateway::cachePutAddedCount cache.puts.added{result=updated} -> StatisticsGateway::cachePutAddedCount cache.misses{reason=expired} -> StatisticsGateway::cacheMissExpiredCount) cache.misses{reason=notFound} -> StatisticsGateway::cacheMissNotFoundCount) cache.xa.commits{result=readOnly} -> StatisticsGateway::xaCommitReadOnlyCount cache.xa.commits{result=exception} -> StatisticsGateway::xaCommitExceptionCount cache.xa.commits{result=committed} -> StatisticsGateway::xaCommitCommittedCount cache.xa.rollbacks{result=exception} -> StatisticsGateway::xaRollbackExceptionCount cache.xa.rollbacks{result=success} -> StatisticsGateway::xaRollbackSuccessCount cache.xa.recoveries{result=nothing} -> StatisticsGateway::xaRecoveryNothingCount cache.xa.recoveries{result=success} -> StatisticsGateway::xaRecoveryRecoveredCount cache.local.offheap.size -> StatisticsGateway::getLocalOffHeapSize) cache.local.heap.size -> StatisticsGateway::getLocalHeapSizeInBytes cache.local.disk.size -> StatisticsGateway::getLocalDiskSizeInBytes 

注冊 MeterBinders 是非常簡單的,示例可以在 micrometer 文檔 中被找到。

記住,您可以手動操作: 

  1. new ClassLoaderMetrics().bindTo(registry);  
  2. new JvmMemoryMetrics().bindTo(registry);  
  3. new EhCache2Metrics(cache, Tags.of("name", cache.getName())).bindTo(registry)  
  4. new TomcatMetrics(manager, tags).bindTo(registry)  
  5. ... 

或者,您可以使用 Spring Boot ,它會在引擎下為您做這件事。

正如我之前提到的,actuator 將提供許多 AutoConfiguration s 和 MetricsBinders ,只要添加給定的依賴項,它就會注冊 MeterBinders 。

例如, TomcatMetricsBinder 將注冊 TomcatMetrics (為您的嵌入式容器)。MeterRegistryConfigurer 將注冊 JVM 、運行時間 和其他系統(tǒng)指標。

現(xiàn)在,假設(shè)您想在您的應用程序中使用 Ehcache 。您可以添加兩個依賴項:   

  1. implementation("org.springframework.boot:spring-boot-starter-cache")  
  2.    implementation("net.sf.ehcache:ehcache") 

然后注冊緩存(您也可以通過 ehcache.xml 來實現(xiàn)) 

  1. @Bean  
  2.    Cache playCache(EhCacheCacheManager cacheManager) {  
  3.        CacheConfiguration cacheConfiguration = new CacheConfiguration()  
  4.            .name(CACHE_NAME)  
  5.            .maxEntriesLocalHeap(MAX_ELEMENTS_IN_MEMORY);  
  6.        Cache cache = new Cache(cacheConfiguration);  
  7.        cacheManager.getCacheManager().addCache(cache);  
  8.        cacheManager.initializeCaches();  
  9.        return cache;  
  10.    } 

現(xiàn)在, CacheMetricsRegistrarConfiguration 將通過 Spring 緩存管理器為每一個緩存管理注冊 EhCache2Metrics 。

如果您不想使用 Spring 緩存管理,您也可以自己注冊 EhCache2Metrics 。

現(xiàn)在,啟動應用程序,您將看到其他 ehcache 指標。 

  1. 2019-07-17 13:08:45.113  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.gets{cache=playCache,cacheManagercacheManager=cacheManager,name=playCache,result=hitthroughput=12.95/s 
  2. 2019-07-17 13:08:45.124  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.misses{cache=playCache,cacheManagercacheManager=cacheManager,name=playCache,reason=notFoundthroughput=3.7/s 
  3. 2019-07-17 13:08:45.124  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.gets{cache=playCache,cacheManagercacheManager=cacheManager,name=playCache,result=missthroughput=3.7/s 
  4. 2019-07-17 13:08:48.840  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.puts{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachethroughput=16.65/s 
  5. 2019-07-17 13:08:48.840  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.misses{cache=playCache,cacheManagercacheManager=cacheManager,name=playCache,reason=notFoundthroughput=3.7/s 
  6. 2019-07-17 13:08:48.841  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.puts{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachethroughput=16.65/s 
  7. 2019-07-17 13:08:48.841  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.puts.added{cache=playCache,cacheManagercacheManager=cacheManager,name=playCache,result=updatedthroughput=0.116667/s 
  8. 2019-07-17 13:08:48.841  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.puts.added{cache=playCache,cacheManagercacheManager=cacheManager,name=playCache,result=updatedthroughput=0.116667/s 
  9. 2019-07-17 13:08:48.841  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.puts.added{cache=playCache,cacheManagercacheManager=cacheManager,name=playCache,result=addedthroughput=0.116667/s 
  10. 2019-07-17 13:08:48.842  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.puts.added{cache=playCache,cacheManagercacheManager=cacheManager,name=playCache,result=addedthroughput=0.116667/s 
  11. 2019-07-17 13:08:48.847  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.local.disk.size{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachevalue=0 B 
  12. 2019-07-17 13:08:48.847  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.local.disk.size{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachevalue=0 B 
  13. 2019-07-17 13:08:48.908  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.local.heap.size{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachevalue=1.039062 KiB 
  14. 2019-07-17 13:08:48.908  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.local.heap.size{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachevalue=1.039062 KiB 
  15. 2019-07-17 13:08:48.909  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.local.offheap.size{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachevalue=0 B 
  16. 2019-07-17 13:08:48.909  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.local.offheap.size{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachevalue=0 B 
  17. 2019-07-17 13:08:48.909  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.remoteSize{} value=0 
  18. 2019-07-17 13:08:48.909  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.remoteSize{} value=0 
  19. 2019-07-17 13:08:48.909  INFO 93052 --- [       Thread-4] i.m.c.i.logging.LoggingMeterRegistry     : cache.size{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachevalue=7 
  20. 2019-07-17 13:08:48.909  INFO 93052 --- [trics-publisher] i.m.c.i.logging.LoggingMeterRegistry     : cache.size{cache=playCache,cacheManagercacheManager=cacheManager,name=playCachevalue=7 

 在這種情況下,指標上下文中每個組件的職責可歸納為:

Ehcache 指標架構(gòu)

您可以在 此處 提供的示例應用中查看所有這些概念。 

 

責任編輯:龐桂玉 來源: Java技術(shù)棧
相關(guān)推薦

2024-08-07 15:27:50

2020-03-20 08:16:54

Cat.1關(guān)系物聯(lián)網(wǎng)

2019-08-15 10:56:10

WebServletSpring mvc

2022-04-13 09:34:52

軟件開發(fā)嵌入式軟件

2020-07-23 07:46:47

機器學習技術(shù)工具

2023-02-10 10:44:26

2020-12-31 07:55:33

spring bootMybatis數(shù)據(jù)庫

2021-12-31 08:48:23

Logback日志管理

2021-11-16 11:45:00

SpringSpring ClouJava

2012-09-10 09:50:40

2022-11-01 08:55:55

編譯工具MavenSpring

2022-04-28 08:05:05

數(shù)據(jù)庫數(shù)據(jù)庫交互

2024-09-27 12:27:31

2021-09-18 16:10:48

Spring BootJava微服務

2025-02-27 13:00:00

SpringBoot數(shù)據(jù)鑒權(quán)代碼

2023-09-16 13:47:47

人工智能數(shù)據(jù)

2025-02-25 00:11:40

Servlet服務器Web

2024-06-14 08:19:45

2025-01-17 09:11:51

2024-01-22 08:46:37

MyBatis數(shù)據(jù)脫敏Spring
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 中文字幕免费在线 | 亚洲二区视频 | 二区av| 亚洲国产一区在线 | 成人亚洲一区 | 精品国产乱码久久久久久1区2区 | 欧美精品一区二区三区在线 | 国内精品一区二区 | 国产一区二区在线看 | 欧美日韩在线一区二区三区 | 美女午夜影院 | 视频1区 | 久久国产精品精品国产色婷婷 | 成人在线观看免费视频 | 国产精品1区2区3区 国产在线观看一区 | 天堂在线1 | 婷婷在线视频 | 久久人人国产 | 男女啪啪高潮无遮挡免费动态 | 人人cao| 国产精品久久久久久模特 | 国产视频精品免费 | 男人天堂网址 | 国产成人免费视频网站高清观看视频 | 国产精品久久久久一区二区三区 | 性一交一乱一透一a级 | 国产三级精品视频 | 91九色视频| 国产这里只有精品 | 国产目拍亚洲精品99久久精品 | 欧美久久久久久久 | 一区二区在线 | 91国内精精品久久久久久婷婷 | 爱爱视频在线观看 | 成人免费黄色片 | 欧美一区二区 | 免费一区二区三区在线视频 | 久久久亚洲 | 色综合成人网 | 亚洲精品视频三区 | 亚洲免费观看 |