Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >聊聊springboot2的micrometer

聊聊springboot2的micrometer

作者头像
code4it
发布于 2018-09-17 08:00:35
发布于 2018-09-17 08:00:35
2.2K00
代码可运行
举报
文章被收录于专栏:码匠的流水账码匠的流水账
运行总次数:0
代码可运行

本文主要研究下springboot2的micrometer

micrometer

springboot2在spring-boot-actuator中引入了micrometer,对1.x的metrics进行了重构,另外支持对接的监控系统也更加丰富(Atlas、Datadog、Ganglia、Graphite、Influx、JMX、NewRelic、Prometheus、SignalFx、StatsD、Wavefront)。1.x的metrics都有点对齐dropwizard-metrics的味道,而micrometer除了一些基本metrics与dropwizard-metrics相类似外,重点支持了tag。这是一个很重要的信号,标志着老一代的statsd、graphite逐步让步于支持tag的influx以及prometheus

etsy原版的statsd是不支持tag的,不过datadog以及influx都有对statsd进行改良以支持tag。而influxdb以及prometheus则是天生支持tag的。

对比

  • dropwizard-metrics guage final Gauge<Long> sizeGauge = new Gauge<Long>() { @Override public Long getValue() { return bufferPoolMXBean.getCount(); } };
  • micrometer Gauge gauge = Gauge .builder("gauge", myObj, myObj::gaugeValue) .description("a description of what this gauge does") // optional .tags("region", "test") // optional .register(registry); 可以看到micrometer支持tag

metrics tag/label

关于metrics是否支持tag/label,则代表其metrics是否能够有多维度的支持。像statsd不支持tag,如果要区分多host的同一个jvm指标,则通常是通过添加prefix来解决,不过这个给查询统计以及后续扩展带了诸多的不变。

支持tag的好处就是可以进行多维度的统计和查询,以同一微服务但是不同实例的jvm指标来说,可以通过tag来添加host标识,这样监控系统就可以灵活根据tag查询过滤来查看不同主机粒度的,甚至是不同数据中心的粒度。

Prometheus

springboot2启用/actuator/prometheus端点,供Prometheus来抓取指标。

maven

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>

配置

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
management.endpoints.web.exposure.include=*

/actuator/prometheus

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# HELP process_cpu_usage The "recent cpu usage" for the Java Virtual Machine process
# TYPE process_cpu_usage gauge
process_cpu_usage 0.0
# HELP tomcat_global_request_seconds  
# TYPE tomcat_global_request_seconds summary
tomcat_global_request_seconds_count{name="http-nio-8080",} 2.0
tomcat_global_request_seconds_sum{name="http-nio-8080",} 0.111
# HELP tomcat_global_received_bytes_total  
# TYPE tomcat_global_received_bytes_total counter
tomcat_global_received_bytes_total{name="http-nio-8080",} 0.0
# HELP jvm_buffer_count An estimate of the number of buffers in the pool
# TYPE jvm_buffer_count gauge
jvm_buffer_count{id="mapped",} 0.0
jvm_buffer_count{id="direct",} 4.0
# HELP jvm_threads_live The current number of live threads including both daemon and non-daemon threads
# TYPE jvm_threads_live gauge
jvm_threads_live 43.0
# HELP process_files_open The open file descriptor count
# TYPE process_files_open gauge
process_files_open 84.0
# HELP tomcat_threads_current  
# TYPE tomcat_threads_current gauge
tomcat_threads_current{name="http-nio-8080",} 10.0
# HELP tomcat_servlet_error_total  
# TYPE tomcat_servlet_error_total counter
tomcat_servlet_error_total{name="default",} 0.0
# HELP process_start_time_seconds The start time of the Java virtual machine
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.521297826521E9
# HELP tomcat_sessions_active_max  
# TYPE tomcat_sessions_active_max gauge
tomcat_sessions_active_max 0.0
# HELP tomcat_servlet_request_max_seconds  
# TYPE tomcat_servlet_request_max_seconds gauge
tomcat_servlet_request_max_seconds{name="default",} 0.0
# HELP jvm_memory_used_bytes The amount of used memory
# TYPE jvm_memory_used_bytes gauge
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-nmethods'",} 3073408.0
jvm_memory_used_bytes{area="nonheap",id="Metaspace",} 4.2002072E7
jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space",} 5467256.0
jvm_memory_used_bytes{area="heap",id="G1 Eden Space",} 1.05906176E8
jvm_memory_used_bytes{area="heap",id="G1 Old Gen",} 1.8914304E7
jvm_memory_used_bytes{area="heap",id="G1 Survivor Space",} 1.048576E7
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'",} 9643520.0
# HELP tomcat_sessions_rejected_total  
# TYPE tomcat_sessions_rejected_total counter
tomcat_sessions_rejected_total 0.0
# HELP system_load_average_1m The sum of the number of runnable entities queued to available processors and the number of runnable entities running on the available processors averaged over a period of time
# TYPE system_load_average_1m gauge
system_load_average_1m 3.796875
# HELP tomcat_threads_config_max  
# TYPE tomcat_threads_config_max gauge
tomcat_threads_config_max{name="http-nio-8080",} 200.0
# HELP tomcat_cache_hit_total  
# TYPE tomcat_cache_hit_total counter
tomcat_cache_hit_total 0.0
# HELP tomcat_sessions_active_current  
# TYPE tomcat_sessions_active_current gauge
tomcat_sessions_active_current 0.0
# HELP jvm_gc_pause_seconds Time spent in GC pause
# TYPE jvm_gc_pause_seconds summary
jvm_gc_pause_seconds_count{action="end of minor GC",cause="Metadata GC Threshold",} 1.0
jvm_gc_pause_seconds_sum{action="end of minor GC",cause="Metadata GC Threshold",} 0.017
jvm_gc_pause_seconds_max{action="end of minor GC",cause="Metadata GC Threshold",} 0.017
jvm_gc_pause_seconds_count{action="end of minor GC",cause="G1 Evacuation Pause",} 1.0
jvm_gc_pause_seconds_sum{action="end of minor GC",cause="G1 Evacuation Pause",} 0.019
jvm_gc_pause_seconds_max{action="end of minor GC",cause="G1 Evacuation Pause",} 0.019
# HELP logback_events_total Number of error level events that made it to the logs
# TYPE logback_events_total counter
logback_events_total{level="error",} 0.0
logback_events_total{level="warn",} 0.0
logback_events_total{level="info",} 39.0
logback_events_total{level="debug",} 0.0
logback_events_total{level="trace",} 0.0
# HELP jvm_gc_memory_promoted_bytes_total Count of positive increases in the size of the old generation memory pool before GC to after GC
# TYPE jvm_gc_memory_promoted_bytes_total counter
jvm_gc_memory_promoted_bytes_total 0.0
# HELP jvm_buffer_total_capacity_bytes An estimate of the total capacity of the buffers in this pool
# TYPE jvm_buffer_total_capacity_bytes gauge
jvm_buffer_total_capacity_bytes{id="mapped",} 0.0
jvm_buffer_total_capacity_bytes{id="direct",} 32768.0
# HELP jvm_classes_loaded The number of classes that are currently loaded in the Java virtual machine
# TYPE jvm_classes_loaded gauge
jvm_classes_loaded 8219.0
# HELP jvm_classes_unloaded_total The total number of classes unloaded since the Java virtual machine has started execution
# TYPE jvm_classes_unloaded_total counter
jvm_classes_unloaded_total 0.0
# HELP tomcat_sessions_alive_max_seconds  
# TYPE tomcat_sessions_alive_max_seconds gauge
tomcat_sessions_alive_max_seconds 0.0
# HELP jvm_gc_max_data_size_bytes Max size of old generation memory pool
# TYPE jvm_gc_max_data_size_bytes gauge
jvm_gc_max_data_size_bytes -1.0
# HELP tomcat_sessions_created_total  
# TYPE tomcat_sessions_created_total counter
tomcat_sessions_created_total 0.0
# HELP system_cpu_usage The "recent cpu usage" for the whole system
# TYPE system_cpu_usage gauge
system_cpu_usage 0.0
# HELP jvm_threads_daemon The current number of live daemon threads
# TYPE jvm_threads_daemon gauge
jvm_threads_daemon 41.0
# HELP system_cpu_count The number of processors available to the Java virtual machine
# TYPE system_cpu_count gauge
system_cpu_count 8.0
# HELP jvm_memory_max_bytes The maximum amount of memory in bytes that can be used for memory management
# TYPE jvm_memory_max_bytes gauge
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'non-nmethods'",} 7553024.0
jvm_memory_max_bytes{area="nonheap",id="Metaspace",} -1.0
jvm_memory_max_bytes{area="nonheap",id="Compressed Class Space",} 1.073741824E9
jvm_memory_max_bytes{area="heap",id="G1 Eden Space",} -1.0
jvm_memory_max_bytes{area="heap",id="G1 Old Gen",} 4.294967296E9
jvm_memory_max_bytes{area="heap",id="G1 Survivor Space",} -1.0
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'",} 2.44105216E8
# HELP tomcat_sessions_expired_total  
# TYPE tomcat_sessions_expired_total counter
tomcat_sessions_expired_total 0.0
# HELP tomcat_global_sent_bytes_total  
# TYPE tomcat_global_sent_bytes_total counter
tomcat_global_sent_bytes_total{name="http-nio-8080",} 2524.0
# HELP tomcat_global_error_total  
# TYPE tomcat_global_error_total counter
tomcat_global_error_total{name="http-nio-8080",} 0.0
# HELP process_files_max The maximum file descriptor count
# TYPE process_files_max gauge
process_files_max 10240.0
# HELP jvm_gc_live_data_size_bytes Size of old generation memory pool after a full GC
# TYPE jvm_gc_live_data_size_bytes gauge
jvm_gc_live_data_size_bytes 0.0
# HELP jvm_gc_memory_allocated_bytes_total Incremented for an increase in the size of the young generation memory pool after one GC to before the next
# TYPE jvm_gc_memory_allocated_bytes_total counter
jvm_gc_memory_allocated_bytes_total 4977768.0
# HELP tomcat_threads_busy  
# TYPE tomcat_threads_busy gauge
tomcat_threads_busy{name="http-nio-8080",} 1.0
# HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for  the Java virtual machine to use
# TYPE jvm_memory_committed_bytes gauge
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-nmethods'",} 3080192.0
jvm_memory_committed_bytes{area="nonheap",id="Metaspace",} 4.5088768E7
jvm_memory_committed_bytes{area="nonheap",id="Compressed Class Space",} 6029312.0
jvm_memory_committed_bytes{area="heap",id="G1 Eden Space",} 1.92937984E8
jvm_memory_committed_bytes{area="heap",id="G1 Old Gen",} 1.19537664E8
jvm_memory_committed_bytes{area="heap",id="G1 Survivor Space",} 1.048576E7
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'",} 9699328.0
# HELP jvm_threads_peak The peak live thread count since the Java virtual machine started or peak was reset
# TYPE jvm_threads_peak gauge
jvm_threads_peak 49.0
# HELP http_server_requests_seconds  
# TYPE http_server_requests_seconds summary
http_server_requests_seconds_count{exception="None",method="GET",status="200",uri="/actuator",} 1.0
http_server_requests_seconds_sum{exception="None",method="GET",status="200",uri="/actuator",} 0.046773049
http_server_requests_seconds_max{exception="None",method="GET",status="200",uri="/actuator",} 0.046773049
http_server_requests_seconds_count{exception="None",method="GET",status="200",uri="/**/favicon.ico",} 1.0
http_server_requests_seconds_sum{exception="None",method="GET",status="200",uri="/**/favicon.ico",} 0.020588395
http_server_requests_seconds_max{exception="None",method="GET",status="200",uri="/**/favicon.ico",} 0.020588395
# HELP jvm_buffer_memory_used_bytes An estimate of the memory that the Java virtual machine is using for this buffer pool
# TYPE jvm_buffer_memory_used_bytes gauge
jvm_buffer_memory_used_bytes{id="mapped",} 0.0
jvm_buffer_memory_used_bytes{id="direct",} 32768.0
# HELP tomcat_global_request_max_seconds  
# TYPE tomcat_global_request_max_seconds gauge
tomcat_global_request_max_seconds{name="http-nio-8080",} 0.087
# HELP tomcat_cache_access_total  
# TYPE tomcat_cache_access_total counter
tomcat_cache_access_total 0.0
# HELP tomcat_servlet_request_seconds  
# TYPE tomcat_servlet_request_seconds summary
tomcat_servlet_request_seconds_count{name="default",} 0.0
tomcat_servlet_request_seconds_sum{name="default",} 0.0
# HELP process_uptime_seconds The uptime of the Java virtual machine
# TYPE process_uptime_seconds gauge
process_uptime_seconds 14.232

比如jvm_memory_used_bytes

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-nmethods'",} 3073408.0
jvm_memory_used_bytes{area="nonheap",id="Metaspace",} 4.2002072E7
jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space",} 5467256.0
jvm_memory_used_bytes{area="heap",id="G1 Eden Space",} 1.05906176E8
jvm_memory_used_bytes{area="heap",id="G1 Old Gen",} 1.8914304E7
jvm_memory_used_bytes{area="heap",id="G1 Survivor Space",} 1.048576E7
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'",} 9643520.0

括号里头的就tag/label,查询的时候就可以使用jvm_memory_used_bytes或者jvm_memory_used_bytes{area=”nonheap”}或者jvm_memory_used_bytes{area=”nonheap”,id=”Metaspace”}等配合tag/label进行查询。

小结

springboot2的micrometer支持了tag/label,配合支持tag/label的监控系统,使得我们可以更加方便地对metrics进行多维度的统计查询及监控。

doc

  • metrics.dropwizard
  • Support for Statsd Tags/Dimensions #1536
  • Getting Started with Sending StatsD Metrics to Telegraf & InfluxDB
  • How can I send multiple tags in statsd #567
  • Using Prometheus in Grafana
  • prometheus QUERY EXAMPLES
  • Using Micrometer With Spring Boot 2
  • Micrometer: Spring Boot 2’s new application metrics collector
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2018-03-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码匠的流水账 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Spring Boot 2.x监控数据可视化(Actuator + Prometheus + Grafana手把手图文教程)
众所周知,Spring Boot有个子项目Spring Boot Actuator,它为应用提供了强大的监控能力。从Spring Boot 2.0开始,Actuator将底层改为Micrometer,提供了更强、更灵活的监控能力。Micrometer是一个监控门面,可以类比成监控界的 Slf4j 。
用户1516716
2019/05/13
2.3K0
Spring Boot 2.x监控数据可视化(Actuator + Prometheus + Grafana手把手图文教程)
Actuator + Prometheus + Grafana搭建微服务监控平台
本文的主要目的是实现微服务的监控,简单了解了上述工具的概念后,我们就来动手实践一下。首先创建一个简单的Spring Boot项目,其主要依赖如下:
端碗吹水
2020/09/23
2.7K0
Actuator + Prometheus + Grafana搭建微服务监控平台
Spring Boot 3.x接入micrometer
可观察性可以通过分布式系统下各种组件交互的可见性来帮助识别应用程序中的问题和调试问题。
eeaters
2023/08/02
4K2
Spring Boot 3.x接入micrometer
做了ERROR日志监控就够了吗?不试一下微服务的JVM监控
现在好多公司都在使用微服务,也有一些公司在落地DDD在业务中,那么你的服务做了监控了吗?一般除了错误日志的监控,报警发邮件、飞书消息或者短信,还有的对数据库或者服务器做了一些监控,那么你对你的服务的JVM层面做了监控吗?
xdd
2022/07/12
8110
做了ERROR日志监控就够了吗?不试一下微服务的JVM监控
【SpringBoot系列】微服务下的指标监测及自定义指标
可观测性是微服务架构的关键特征,应用程序指标是程序可观察性的一个维度,当应用程序在生产环境中运行时,我们可能想知道各种操作指标,如内存、CPU、线程池使用率等,以及业务指标,例如对特定操作发出了多少请求。
Freedom123
2024/04/22
3670
springboot2上报metrics到statsd
micrometer-registry-statsd-1.0.1-sources.jar!/io/micrometer/statsd/StatsdFlavor.java
code4it
2018/09/17
1.3K0
springboot集成普罗米修斯
Prometheus 是一套开源的系统监控报警框架。它由工作在 SoundCloud 的 员工创建,并在 2015 年正式发布的开源项目。2016 年,Prometheus 正式加入 Cloud Native Computing Foundation,非常的受欢迎。
方志朋
2022/01/06
1.8K0
springboot集成普罗米修斯
Spring Boot整合 Prometheus
Micrometer 为 Java 平台上的性能数据收集提供了一个通用的 API,应用程序只需要使用 Micrometer 的通用 API 来收集性能指标即可。Micrometer 会负责完成与不同监控系统的适配工作。这就使得切换监控系统变得很容易。Micrometer 还支持推送数据到多个不同的监控系统。Micrometer类似日志系统中SLF4J。
BUG弄潮儿
2021/08/13
1.5K0
聊聊springboot1.x及2.x的JvmGcMetrics的区别
本文主要研究一下springboot1.x及2.x的JvmGcMetrics的区别
code4it
2018/09/17
1.2K0
PromQL之选择器和运算符
例:查询 2023-01-18 19:08:59 的 jvm_memory_used_bytes 指标
阿提说说
2023/02/02
1.2K0
PromQL之选择器和运算符
springboot2增加diskspace指标
spring-boot-actuator-autoconfigure-2.0.1.RELEASE-sources.jar!/org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthIndicatorProperties.java
code4it
2018/09/17
1.7K0
SpringBoot Actuator — 埋点和监控
监控机器环境的性能和业务流程或逻辑等各项数据,并根据这些数据生成对应的指标,那么我们就称为数据埋点。比如我们想知道某个接口调用的 TPS、机器 CPU 的使用率,这些都可以用到数据埋点
晚上没宵夜
2021/11/16
1.4K0
聊聊springboot的TomcatMetricsBinder
org/springframework/boot/actuate/autoconfigure/metrics/web/tomcat/TomcatMetricsAutoConfiguration.java
code4it
2023/10/27
2000
SpringBoot掌握的差不多了,就剩下一个Actuator没搞定了,本文详细来介绍!!!
  通过前面的介绍我们明白了SpringBoot为什么能够很方便快捷的构建Web应用,那么应用部署上线后的健康问题怎么发现呢?在SpringBoot中给我们提供了Actuator来解决这个问题。
用户4919348
2021/09/08
1.6K0
SpringBoot掌握的差不多了,就剩下一个Actuator没搞定了,本文详细来介绍!!!
聊聊jvm的Code Cache
JVM生成的native code存放的内存空间称之为Code Cache;JIT编译、JNI等都会编译代码到native code,其中JIT生成的native code占用了Code Cache的绝大部分空间
code4it
2019/03/30
7.9K0
聊聊jvm的Code Cache
给你的SpringBoot做埋点监控--JVM应用度量框架Micrometer
spring-actuator做度量统计收集,使用Prometheus(普罗米修斯)进行数据收集,Grafana(增强ui)进行数据展示,用于监控生成环境机器的性能指标和业务数据指标。一般,我们叫这样的操作为”埋点”。SpringBoot中的依赖spring-actuator中集成的度量统计API使用的框架是Micrometer,官网是Micrometer.io。在实践中发现了业务开发者滥用了Micrometer的度量类型Counter,导致无论什么情况下都只使用计数统计的功能。这篇文章就是基于Micrometer分析其他的度量类型API的作用和适用场景。
云扬四海
2019/08/14
5.3K0
Spring Boot 使用 Micrometer 集成 Prometheus 监控 Java 应用性能
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
哎_小羊
2019/09/18
10.5K0
Spring Boot 使用 Micrometer 集成 Prometheus 监控 Java 应用性能
Spring Boot Actuators
Spring Boot 提供了开箱即用的应用监控功能,对于大厂来说可能比较鸡肋,但是对于一些没有基础建设团队的中小公司是非常好用的。
李鸿坤
2020/09/24
3830
聊聊springboot的TomcatMetricsBinder
org/springframework/boot/actuate/autoconfigure/metrics/web/tomcat/TomcatMetricsAutoConfiguration.java
code4it
2023/10/30
2810
聊聊springboot的TomcatMetricsBinder
SpringBoot健康检查,如何与容器配合?
http://xjjdog.cn 对200+原创文章进行了细致的分类,阅读更流畅,欢迎收藏。
xjjdog
2020/12/11
7160
SpringBoot健康检查,如何与容器配合?
推荐阅读
相关推荐
Spring Boot 2.x监控数据可视化(Actuator + Prometheus + Grafana手把手图文教程)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验