• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

springboot2.X整合prometheus监控的实例讲解

springboot 搞代码 4年前 (2022-01-09) 26次浏览 已收录 0个评论
文章目录[隐藏]

springboot2.x暴露健康状况通过prometheus监控

加入依赖

 <!--prometheus监控 https://prometheus.io/docs/introduction/overview/-->
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-actuator</artifactId>
 </dependency>
 <dependency>
 <groupId>io.micrometer</groupId>
 <artifactId>micrometer-registry-prometheus</artifactId>
 </dependency>
 <!--prometheus监控 https://prometheus.io/docs/introduction/overview/-->

application.yml加入相关配置

management:
 security:
 enabled: false
 #prometheus+grafana+springboot2监控集成配置
 metrics:
 export:
 prometheus:
 enabled: true
 jmx:
 enabled: true
 endpoints:
 web:
 exposure:
 include: '*'
 base-path: /metrics
 #prometheus+grafana+springboot2监控集成配置

主启动类加入配置

package com.drore.saas;
import com.drore.saas.services.service.StorageService;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@ServletComponentScan
public class TenantappApplication {
 public static void main(String[] args) {
 SpringApplication.run(TenantappApplication.class, args);
 }
 @Bean
 CommandLineRunner init(StorageService storageService) {
 return (args) -> {
 storageService.init();
 };
 }
#prometheus+grafana+springboot2监控集成配置
 @Bean
 MeterRegistryCustomizer meterRegistryCustomizer(MeterRegistry meterRegistry) {
 return meterRegistry1 -> {
 meterRegistry.config()
 .commonTags("application", "Tenantapp");
 };
 }
 #prometheus+grafana+springboot2监控集成配置
}

启动之后通过路径访问查看健康状况

http://xxxxxx/metrics/prometheus

查看到的数据如下:

[root@saas98 /]$ curl "http://10.98.94.220:80/ts/metrics/prometheus"
# HELP process_start_time_seconds Start time of the process since unix epoch.
# TYPE process_start_time_seconds gauge
process_start_time_seconds{application="Tenantapp",} 1.556068841226E9
# HELP tomcat_threads_busy_threads 
# TYPE tomcat_threads_busy_threads gauge
tomcat_threads_busy_threads{application="Tenantapp",name="http-nio-9081",} 1.0
# HELP tomcat_sessions_expired_sessions_total 
# TYPE tomcat_sessions_expired_sessions_total counter
tomcat_sessions_expired_sessions_total{application="Tenantapp",} 0<b style="color:transparent">本文来源gao@!dai!ma.com搞$$代^@码!网!</b>.0
# HELP tomcat_sessions_active_current_sessions 
# TYPE tomcat_sessions_active_current_sessions gauge
tomcat_sessions_active_current_sessions{application="Tenantapp",} 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{application="Tenantapp",} 1.18894656E8
# HELP tomcat_global_request_max_seconds 
# TYPE tomcat_global_request_max_seconds gauge
tomcat_global_request_max_seconds{application="Tenantapp",name="http-nio-9081",} 3.366
# HELP jvm_memory_used_bytes The amount of used memory
# TYPE jvm_memory_used_bytes gauge
jvm_memory_used_bytes{application="Tenantapp",area="heap",id="Survivor Space",} 653880.0
jvm_memory_used_bytes{application="Tenantapp",area="nonheap",id="Metaspace",} 1.36445248E8
jvm_memory_used_bytes{application="Tenantapp",area="heap",id="Eden Space",} 7511504.0
jvm_memory_used_bytes{application="Tenantapp",area="nonheap",id="Code Cache",} 3.8031424E7
jvm_memory_used_bytes{application="Tenantapp",area="heap",id="Tenured Gen",} 1.3880212E8
jvm_memory_used_bytes{application="Tenantapp",area="nonheap",id="Compressed Class Space",} 1.7220968E7
# HELP tomcat_sessions_created_sessions_total 
# TYPE tomcat_sessions_created_sessions_total counter
tomcat_sessions_created_sessions_total{application="Tenantapp",} 0.0
# HELP system_cpu_count The number of processors available to the Java virtual machine
# TYPE system_cpu_count gauge
system_cpu_count{application="Tenantapp",} 1.0
# HELP tomcat_global_sent_bytes_total 
# TYPE tomcat_global_sent_bytes_total counter
tomcat_global_sent_bytes_total{application="Tenantapp",name="http-nio-9081",} 8168269.0
# HELP jvm_threads_daemon_threads The current number of live daemon threads
# TYPE jvm_threads_daemon_threads gauge
jvm_threads_daemon_threads{application="Tenantapp",} 34.0
# HELP logback_events_total Number of error level events that made it to the logs
# TYPE logback_events_total counter
logback_events_total{application="Tenantapp",level="debug",} 0.0
logback_events_total{application="Tenantapp",level="error",} 965.0
logback_events_total{application="Tenantapp",level="warn",} 4.0
logback_events_total{application="Tenantapp",level="info",} 1047.0
logback_events_total{application="Tenantapp",level="trace",} 0.0
# HELP tomcat_cache_access_total 
# TYPE tomcat_cache_access_total counter
tomcat_cache_access_total{application="Tenantapp",} 0.0
# HELP tomcat_servlet_error_total 
# TYPE tomcat_servlet_error_total counter
tomcat_servlet_error_total{application="Tenantapp",name="dispatcherServlet",} 0.0
tomcat_servlet_error_total{application="Tenantapp",name="statViewServlet",} 0.0
tomcat_servlet_error_total{application="Tenantapp",name="default",} 0.0
# HELP jvm_buffer_total_capacity_bytes An estimate of the total capacity of the buffers in this pool

prometheus-operator监控java应用整合


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:springboot2.X整合prometheus监控的实例讲解
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址