prometheus监控springboot2.X项⽬各种默认指标,⾃定义接⼝
性能错误及其。。。
1/⽅案
通过Micrometer+actuator暴露拉取metric的端点给Prometheus,通过grafana导⼊相关优秀模板进⾏展⽰,其中增加了⾃定义指标并dashboard追加⾃定义panel的展⽰。
2/依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
3/配置
#Prometheus springboot监控配置
management:
endpoints:
web:
幼儿思维
exposure:
include: 'prometheus' # 暴露/actuator/prometheus
你可知道我想你
metrics:
tags:
application: ${spring.application.name} # 暴露的数据中添加application label
4/挑选模板,推荐选⽤12856,Prometheus追加配置并重启
因为Prometheus⽬前不只⽀持基于consul,file等的服务发现,暂时只能使⽤静态配置static_configs
#抓取配置
scrape_configs:
- job_name: 'prometheus'
metrics_path: '/metrics' #默认
scheme: 'http' #默认
# scrape_interval: 10s #覆盖全局
# static_configs:
# - targets: ['localhost:9090']
# labels:
# instance: xxx
#安装参考后⾯的node-exporter
- job_name: 'node-exporter'
static_configs:
- targets: ['localhost:9100']
- job_name: 'cadvisor'
付出与收获static_configs:
- targets: ['localhost:9111']
- job_name: "vehicle-payment"
metrics_path: "/actuator/prometheus"
static_configs:
- targets: ["localhost:8880"]
- job_name: "vehicle-lottery"
metrics_path: "/actuator/prometheus"
5/默认监控指标
禁⽌默认指标:通过yml配置项禁⽌指标已deprecated,需要在启动类禁⽌@SpringBootApplication(exclude = {LogbackMetricsAutoConfiguration.class},下⾯便是禁⽌logback⽇志指标后的监控项,主要还有http接⼝请求耗时,hikaricp连接
池,jvm,tomcat,jdbc,系统cpu等
[root@iz2vcbxdfdrfac7remhtorz monitor]# curl localhost:8880/actuator/prometheus
# HELP tomcat_ssions_alive_max_conds
# TYPE tomcat_ssions_alive_max_conds gauge
tomcat_ssions_alive_max_conds{application="payment",} 0.0
# HELP http_rver_requests_conds
# TYPE http_rver_requests_conds summary
http_rver_requests_conds_count{application="payment",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/rvice-order/count-by-s http_rver_requests_conds_sum{application="payment",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/rvice-order/count-by-sta http_rver_requests_conds_count{application="payment",exception="None",method="DELETE",outcome="SUCCESS",status="200",uri="/rvice-order/remov http_rver_requests_conds_sum{application="payment",exception="None",method="DELETE",outcome="SUCCESS",status="200",uri="/rvice-order/remove http_rver_requests_conds_count{application="payment",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 9 http_rver_requests_conds_sum{application="payment",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 0. http_rver_requests_conds_count{application="payment",exception="None",method="GET",o
utcome="SUCCESS",status="200",uri="/rvice-order/page",} 15 http_rver_requests_conds_sum{application="payment",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/rvice-order/page",} 11.6 # HELP http_rver_requests_conds_max
# TYPE http_rver_requests_conds_max gauge
http_rver_requests_conds_max{application="payment",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/rvice-order/count-by-sta http_rver_requests_conds_max{application="payment",exception="None",method="DELETE",outcome="SUCCESS",status="200",uri="/rvice-order/remove http_rver_requests_conds_max{application="payment",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 0. http_rver_requests_conds_max{application="payment",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/rvice-order/page",} 0.0 # HELP tomcat_ssions_rejected_ssions_total
# TYPE tomcat_ssions_rejected_ssions_total counter
tomcat_ssions_rejected_ssions_total{application="payment",} 0.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{application="payment",} 0.0
# HELP hikaricp_connections_max Max connections
# TYPE hikaricp_connections_max gauge
hikaricp_connections_max{application="payment",pool="DatebookHikariCP",} 20.0
# HELP hikaricp_connections_idle Idle connections
# TYPE hikaricp_connections_idle gauge
hikaricp_connections_idle{application="payment",pool="DatebookHikariCP",} 5.0
# HELP system_cpu_usage The "recent cpu usage" for the whole system
# TYPE system_cpu_usage gauge
system_cpu_usage{application="payment",} 0.03063776573572322
# HELP hikaricp_connections_usage_conds Connection usage time
# TYPE hikaricp_connections_usage_conds summary
hikaricp_connections_usage_conds_count{application="payment",pool="DatebookHikariCP",} 39.0
hikaricp_connections_usage_conds_sum{application="payment",pool="DatebookHikariCP",} 0.425
# HELP hikaricp_connections_usage_conds_max Connection usage time
# TYPE hikaricp_connections_usage_conds_max gauge
hikaricp_connections_usage_conds_max{application="payment",pool="DatebookHikariCP",} 0.0
# HELP jvm_threads_live_threads The current number of live threads including both daemon and non-daemon threads
# TYPE jvm_threads_live_threads gauge
jvm_threads_live_threads{application="payment",} 67.0
# HELP jdbc_connections_active
# TYPE jdbc_connections_active gauge
jdbc_connections_active{application="payment",name="dataSource",} 0.0
# HELP jvm_gc_memory_promoted_bytes_total Count of positive increas 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{application="payment",} 2.771068E7
# 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{application="payment",} 0.0
# HELP api_cost_summary 请求耗时summary
# TYPE api_cost_summary summary
api_cost_summary{uri="/rvice-order/remove",accessType="1",code="0",quantile="0.5",} NaN
api_cost_summary{uri="/rvice-order/remove",accessType="1",code="0",quantile="0.9",} NaN
api_cost_summary_count{uri="/rvice-order/remove",accessType="1",code="0",} 4.0
api_cost_summary_count{uri="/rvice-order/remove",accessType="1",code="0",} 4.0
api_cost_summary_sum{uri="/rvice-order/remove",accessType="1",code="0",} 97.0
api_cost_summary{uri="/rvice-order/page",accessType="1",code="0",quantile="0.5",} 19.0
api_cost_summary{uri="/rvice-order/page",accessType="1",code="0",quantile="0.9",} 19.0
api_cost_summary_count{uri="/rvice-order/page",accessType="1",code="0",} 15.0
api_cost_summary_sum{uri="/rvice-order/page",accessType="1",code="0",} 11383.0
# HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for the Java virtual machine to u
# TYPE jvm_memory_committed_bytes gauge
jvm_memory_committed_bytes{application="payment",area="nonheap",id="Metaspace",} 8.3361792E7
jvm_memory_committed_bytes{application="payment",area="heap",id="Par Eden Space",} 2.097152E8
jvm_memory_committed_bytes{application="payment",area="nonheap",id="Code Cache",} 3.1260672E7
jvm_memory_committed_bytes{application="payment",area="heap",id="CMS Old Gen",} 5.767168E8
jvm_memory_committed_bytes{application="payment",area="nonheap",id="Compresd Class Space",} 1.048576E7
jvm_memory_committed_bytes{application="payment",area="heap",id="Par Survivor Space",} 2.62144E7
# HELP process_files_max_files The maximum file descriptor count
# TYPE process_files_max_files gauge
process_files_max_files{application="payment",} 1048576.0
# HELP hikaricp_connections_creation_conds_max Connection creation time
# TYPE hikaricp_connections_creation_conds_max gauge
hikaricp_connections_creation_conds_max{application="payment",pool="DatebookHikariCP",} 0.0
# HELP hikaricp_connections_creation_conds Connection creation time
# TYPE hikaricp_connections_creation_conds summary
hikaricp_connections_creation_conds_count{application="payment",pool="DatebookHikariCP",} 0.0
hikaricp_connections_creation_conds_sum{application="payment",pool="DatebookHikariCP",} 0.0
# HELP api_cost_histogram 请求耗时histogram
# TYPE api_cost_histogram histogram
api_cost_histogram_bucket{uri="/rvice-order/remove",accessType="1",code="0",le="100.0",} 4.0
api_cost_histogram_bucket{uri="/rvice-order/remove",accessType="1",code="0",le="500.0",} 4.0
年会诗朗诵api_cost_histogram_bucket{uri="/rvice-order/remove",accessType="1",code="0",le="1000.0",} 4.0
api_cost_histogram_bucket{uri="/rvice-order/remove",accessType="1",code="0",le="3000.0",} 4.0
api_cost_histogram_bucket{uri="/rvice-order/remove",accessType="1",code="0",le="+Inf",} 4.0
api_cost_histogram_count{uri="/rvice-order/remove",accessType="1",code="0",} 4.0
api_cost_histogram_sum{uri="/rvice-order/remove",accessType="1",code="0",} 97.0
api_cost_histogram_bucket{uri="/rvice-order/page",accessType="1",code="0",le="100.0",} 11.0
生日礼物送什么
api_cost_histogram_bucket{uri="/rvice-order/page",accessType="1",code="0",le="500.0",} 11.0
api_cost_histogram_bucket{uri="/rvice-order/page",accessType="1",code="0",le="1000.0",} 12.0
api_cost_histogram_bucket{uri="/rvice-order/page",accessType="1",code="0",le="3000.0",} 14.0
api_cost_histogram_bucket{uri="/rvice-order/page",accessType="1",code="0",le="+Inf",} 15.0
api_cost_histogram_count{uri="/rvice-order/page",accessType="1",code="0",} 15.0
api_cost_histogram_sum{uri="/rvice-order/page",accessType="1",code="0",} 11383.0
# HELP system_cpu_count The number of processors available to the Java virtual machine
# TYPE system_cpu_count gauge
system_cpu_count{application="payment",} 8.0
# HELP jvm_threads_peak_threads The peak live thread count since the Java virtual machine started or peak was ret
# TYPE jvm_threads_peak_threads gauge
jvm_threads_peak_threads{application="payment",} 71.0
# HELP jvm_class_unloaded_class_total The total number of class unloaded since the Java virtual machine has started execution # TYPE jvm_class_unloaded_class_total counter
jvm_class_unloaded_class_total{application="payment",} 0.0
# HELP jvm_buffer_count_buffers An estimate of the number of buffers in the pool
# TYPE jvm_buffer_count_buffers gauge
jvm_buffer_count_buffers{application="payment",id="mapped",} 0.0
jvm_buffer_count_buffers{application="payment",id="direct",} 11.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{application="payment",id="mapped",} 0.0
jvm_buffer_total_capacity_bytes{application="payment",id="direct",} 81920.0
# HELP tomcat_ssions_active_current_ssions
# TYPE tomcat_ssions_active_current_ssions gauge
tomcat_ssions_active_current_ssions{application="payment",} 0.0
# HELP tomcat_ssions_active_max_ssions
# TYPE tomcat_ssions_active_max_ssions gauge
tomcat_ssions_active_max_ssions{application="payment",} 0.0
# HELP hikaricp_connections_timeout_total Connection timeout total count
# TYPE hikaricp_connections_timeout_total counter
hikaricp_connections_timeout_total{application="payment",pool="DatebookHikariCP",} 0.0
hikaricp_connections_timeout_total{application="payment",pool="DatebookHikariCP",} 0.0
# HELP jvm_memory_ud_bytes The amount of ud memory
# TYPE jvm_memory_ud_bytes gauge
jvm_memory_ud_bytes{application="payment",area="nonheap",id="Metaspace",} 7.8662264E7
jvm_memory_ud_bytes{application="payment",area="heap",id="Par Eden Space",} 8.3274296E7
jvm_memory_ud_bytes{application="payment",area="nonheap",id="Code Cache",} 3.1095872E7
jvm_memory_ud_bytes{application="payment",area="heap",id="CMS Old Gen",} 3.2599328E7
jvm_memory_ud_bytes{application="payment",area="nonheap",id="Compresd Class Space",} 9694744.0
jvm_memory_ud_bytes{application="payment",area="heap",id="Par Survivor Space",} 1.7527368E7
# HELP jdbc_connections_min
# TYPE jdbc_connections_min gauge
jdbc_connections_min{application="payment",name="dataSource",} 5.0
# HELP hikaricp_connections_acquire_conds Connection acquire time
# TYPE hikaricp_connections_acquire_conds summary
hikaricp_connections_acquire_conds_count{application="payment",pool="DatebookHikariCP",} 39.0
hikaricp_connections_acquire_conds_sum{application="payment",pool="DatebookHikariCP",} 0.026086932
# HELP hikaricp_connections_acquire_conds_max Connection acquire time
# TYPE hikaricp_connections_acquire_conds_max gauge
hikaricp_connections_acquire_conds_max{application="payment",pool="DatebookHikariCP",} 0.0
# HELP jdbc_connections_idle
# TYPE jdbc_connections_idle gauge
jdbc_connections_idle{application="payment",name="dataSource",} 5.0庆祝生日
# HELP jvm_buffer_memory_ud_bytes An estimate of the memory that the Java virtual machine is using for this buffer pool
# TYPE jvm_buffer_memory_ud_bytes gauge
jvm_buffer_memory_ud_bytes{application="payment",id="mapped",} 0.0
jvm_buffer_memory_ud_bytes{application="payment",id="direct",} 81921.0
# HELP jvm_threads_states_threads The current number of threads having NEW state
# TYPE jvm_threads_states_threads gauge
jvm_threads_states_threads{application="payment",state="new",} 0.0
jvm_threads_states_threads{application="payment",state="runnable",} 9.0
jvm_threads_states_threads{application="payment",state="blocked",} 0.0
jvm_threads_states_threads{application="payment",state="terminated",} 0.0
jvm_threads_states_threads{application="payment",state="waiting",} 36.0
jvm_threads_states_threads{application="payment",state="timed-waiting",} 22.0
# HELP jvm_gc_memory_allocated_bytes_total Incremented for an increa 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{application="payment",} 1.6777216E9
# HELP api_cost_timer_conds_max
# TYPE api_cost_timer_conds_max gauge
api_cost_timer_conds_max{accessType="1",application="payment",code="0",uri="/rvice-order/page",} 0.0
api_cost_timer_conds_max{accessType="1",application="payment",code="0",uri="/rvice-order/remove",} 0.0
# HELP api_cost_timer_conds
# TYPE api_cost_timer_conds summary
api_cost_timer_conds_count{accessType="1",application="payment",code="0",uri="/rvice-order/page",} 15.0
api_cost_timer_conds_sum{accessType="1",application="payment",code="0",uri="/rvice-order/page",} 11.383
api_cost_timer_conds_count{accessType="1",application="payment",code="0",uri="/rvice-order/remove",} 4.0
api_cost_timer_conds_sum{accessType="1",application="payment",code="0",uri="/rvice-order/remove",} 0.097
# HELP process_start_time_conds Start time of the process since unix epoch.
# TYPE process_start_time_conds gauge
process_start_time_conds{application="payment",} 1.605842727489E9
# HELP tomcat_ssions_expired_ssions_total
# TYPE tomcat_ssions_expired_ssions_total counter
tomcat_ssions_expired_ssions_total{application="payment",} 0.0
# HELP hikaricp_connections Total connections
# TYPE hikaricp_connections gauge
hikaricp_connections{application="payment",pool="DatebookHikariCP",} 5.0
# HELP process_cpu_usage The "recent cpu usage" for the Java Virtual Machine process
# TYPE process_cpu_usage gauge
process_cpu_usage{application="payment",} 0.0034385745545482964
# HELP jvm_threads_daemon_threads The current number of live daemon threads
# TYPE jvm_threads_daemon_threads gauge
jvm_threads_daemon_threads{application="payment",} 62.0
# HELP jvm_class_loaded_class The number of class that are currently loaded in the Java virtual machine
# TYPE jvm_class_loaded_class gauge
jvm_class_loaded_class{application="payment",} 14454.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 th
# HELP system_load_average_1m The sum of the number of runnable entities queued to available processors and the number of runnable entities runnin # TYPE system_load_average_1m gauge
system_load_average_1m{application="payment",} 1.95
# HELP process_files_open_files The open file descriptor count
信任的拼音# TYPE process_files_open_files gauge
process_files_open_files{application="payment",} 75.0
# HELP hikaricp_connections_min Min connections
# TYPE hikaricp_connections_min gauge
hikaricp_connections_min{application="payment",pool="DatebookHikariCP",} 5.0
# HELP jdbc_connections_max
# TYPE jdbc_connections_max gauge
jdbc_connections_max{application="payment",name="dataSource",} 20.0
# HELP hikaricp_connections_pending Pending threads
# TYPE hikaricp_connections_pending gauge
hikaricp_connections_pending{application="payment",pool="DatebookHikariCP",} 0.0
# HELP jvm_gc_pau_conds Time spent in GC pau
# TYPE jvm_gc_pau_conds summary
jvm_gc_pau_conds_count{action="end of minor GC",application="payment",cau="Allocation Failure",} 8.0
jvm_gc_pau_conds_sum{action="end of minor GC",application="payment",cau="Allocation Failure",} 0.304
# HELP jvm_gc_pau_conds_max Time spent in GC pau
# TYPE jvm_gc_pau_conds_max gauge
jvm_gc_pau_conds_max{action="end of minor GC",application="payment",cau="Allocation Failure",} 0.0
# HELP hikaricp_connections_active Active connections
# TYPE hikaricp_connections_active gauge
hikaricp_connections_active{application="payment",pool="DatebookHikariCP",} 0.0石狮精
# HELP tomcat_ssions_created_ssions_total
# TYPE tomcat_ssions_created_ssions_total counter
tomcat_ssions_created_ssions_total{application="payment",} 0.0
# HELP process_uptime_conds The uptime of the Java virtual machine
# TYPE process_uptime_conds gauge
process_uptime_conds{application="payment",} 1185.341
# HELP jvm_memory_max_bytes The maximum amount of memory in bytes that can be ud for memory management
# TYPE jvm_memory_max_bytes gauge
jvm_memory_max_bytes{application="payment",area="nonheap",id="Metaspace",} 2.097152E8
jvm_memory_max_bytes{application="payment",area="heap",id="Par Eden Space",} 2.097152E8
jvm_memory_max_bytes{application="payment",area="nonheap",id="Code Cache",} 2.5165824E8
jvm_memory_max_bytes{application="payment",area="heap",id="CMS Old Gen",} 5.767168E8
jvm_memory_max_bytes{application="payment",area="nonheap",id="Compresd Class Space",} 1.073741824E9
jvm_memory_max_bytes{application="payment",area="heap",id="Par Survivor Space",} 2.62144E7
6/采集⾃定义指标,如请求耗时
默认指标已有请求耗时,但不便⾃定义扩展,考虑⾃⼰采集,⾃定义指标类型有
Counter:只增不减的计数器
Gauge: 可增可减的计数器
Histogram:⾃带buckets区间分布统计,如图请求耗时(毫秒)区间:100,500,1000,3000,+Inf正⽆穷 ,不指定则默认
0.01,0.025,0.05,0.075,....7.5,10,+Inf
Summary: 客户端收集中位数,九分位数的数据指标,不指定则不统计分位数(timmer也属于summary,默认单位ncond,并统计max 值)
↓↓↓
配置收集指标的bean,⾮必须,如本案例只需要⾃动装配的registry,通过registry获取timer收集数据