SpringBoot 2.x监控数据可视化(prometheus+grafana集成配置)

发布一下 0 0

Spring Boot有个子项目Spring Boot Actuator,它为应用提供了强大的监控能力。从Spring Boot 2.0开始,Actuator将底层改为Micrometer,提供了更强、更灵活的监控能力。

springboot集成配置

springboot2.x中提供了actuator作为采集exporter,为prometheus暴露采集端点,只需要在项目依赖中添加以下配置即可。

依赖中添加以下配置(使用maven作为编译工具):

		<!-- actuator and prometheus -->		<dependency>			<groupId>org.springframework.boot</groupId>			<artifactId>spring-boot-starter-actuator</artifactId>		</dependency>		<dependency>			<groupId>io.micrometer</groupId>			<artifactId>micrometer-registry-prometheus</artifactId>		</dependency>		<dependency>			<groupId>io.github.mweirauch</groupId>			<artifactId>micrometer-jvm-extras</artifactId>			<version>0.2.0</version>		</dependency>

在配置文件application.yaml中要增加如下配置:

# actuator+prometheus+grafana+springboot2监控集成配置management:  endpoints:    web:      exposure:        include: 'prometheus' # 暴露/actuator/prometheus  metrics:    tags:      application: ${spring.application.name} # 暴露的数据中添加application label spring:  application:    name: app-server

如配置所示,指定应用名为 app-server ,并将 Actuator 的 /actuator/prometheus 端点暴露出来;

配置完成之后即可在启动应用之后通过http://host:port/actuator/prometheus 访问采集信息。

查看采集信息

配置完成之后启动spring boot应用程序,访问 http://localhost:8080/actuator/prometheus 即可查看采集信息:

SpringBoot 2.x监控数据可视化(prometheus+grafana集成配置)

prometheus的集成配置

在prometheus的配置文件prometheus.yml中添加scrape_configs:

  - job_name: 'app-server'    metrics_path: '/actuator/prometheus'    static_configs:    - targets: ['192.168.0.100:8088']

Grafana可视化

比较好用的两个Dashboard:

JVM (Micrometer) https://grafana.com/grafana/dashboards/4701

JVM (Actuator) https://grafana.com/grafana/dashboards/9568

导入Grafana市场中的Dashboard模板,如下图操作步骤:

SpringBoot 2.x监控数据可视化(prometheus+grafana集成配置)

SpringBoot 2.x监控数据可视化(prometheus+grafana集成配置)

导入4701模板后,即可看到类似如下的界面,囊括了JVM常关心的指标,该Dashboard均已支持!

SpringBoot 2.x监控数据可视化(prometheus+grafana集成配置)

版权声明:内容来源于互联网和用户投稿 如有侵权请联系删除

本文地址:http://0561fc.cn/80389.html