公司需要监控生产环境的程序运行情况,所以引入prometheus来监控应用,效果如下:
与SpringBoot应用程序集成步骤:
1.pom.xml文件添加如下依赖:
<!-- 暴露监控端点 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- prometheus监控 -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.5</version>
</dependency>
2.写配置,application.yml
management:
endpoints:
web:
exposure:
include: "*"
metrics:
tags:
application: ${spring.application.name}
3.运行程序,集成prometheus、grafana
使用grafana模板=4701,选择数据源prometheus即可