1.新增springboot项目
我是用的我上面的那个项目。spring-boot版本2.2.4.RELEASE
2.配置yml文件
management:
endpoint:
prometheus:
enabled: true
jmx:
enabled: true
endpoints:
web:
exposure:
include: '*'
base-path: /metrics
3.引入对应依赖
<!--添加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>
4.添加配置文件
import io.micrometer.core.instrument.MeterRegistry; import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class CommonConfiguration { //prometheus+grafana+springboot2监控集成配置 //访问 http://ip:port/metrics/prometheus // http://localhost:8088/metrics/prometheus @Bean public MeterRegistryCustomizer meterRegistryCustomizer(MeterRegistry meterRegistry) { return meterRegistry1 -> meterRegistry.config().commonTags("application", "AfcPay"); } }
5.启动springboot项目,查看是否成功
访问http://localhost:8088/metrics/prometheus
显示此页面代表配置成功,这些信息都是actuator的一些监控信息。
具体安装操作,借鉴这篇文章看下。
Prometheus 安装与配置_一百减一是零啊的博客-CSDN博客