1. 在 Spring Boot 中的 pom 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
2. 在 SpringBoot 配置文件 application.yml 中配置:
management:
#prometheus+grafana+springboot2监控集成配置
metrics:
export:
prometheus:
enabled: true
jmx:
enabled: true
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
endpoints:
web:
exposure:
include: '*'
base-path: /metrics
3. 最后在 SpringBoot 加入一个 Bean
// prometheus+grafana+springboot2监控集成配置
@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry -> registry.config().commonTags("application", "项目名");
}
// prometheus+grafana+springboot2监控集成配置
4. 这样就算是启动了 springboot 项目的 exporter 了