Commit 4dfa816a5a2c2763c3b0033af185de20fcfba109
1 parent
cca8375a
【新增】集成 Prometheus 监控点
Showing
3 changed files
with
35 additions
and
1 deletions
yudao-framework/yudao-spring-boot-starter-monitor/pom.xml
| ... | ... | @@ -58,6 +58,12 @@ |
| 58 | 58 | <artifactId>apm-toolkit-opentracing</artifactId> |
| 59 | 59 | </dependency> |
| 60 | 60 | |
| 61 | + <!-- Micrometer 对 Prometheus 的支持 --> | |
| 62 | + <dependency> | |
| 63 | + <groupId>io.micrometer</groupId> | |
| 64 | + <artifactId>micrometer-registry-prometheus</artifactId> | |
| 65 | + </dependency> | |
| 66 | + | |
| 61 | 67 | <dependency> |
| 62 | 68 | <groupId>de.codecentric</groupId> |
| 63 | 69 | <artifactId>spring-boot-admin-starter-client</artifactId> <!-- 实现 Spring Boot Admin Server 服务端 --> | ... | ... |
yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoMetricsAutoConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.tracer.config; | |
| 2 | + | |
| 3 | +import io.micrometer.core.instrument.MeterRegistry; | |
| 4 | +import org.springframework.beans.factory.annotation.Value; | |
| 5 | +import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; | |
| 6 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | |
| 7 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
| 8 | +import org.springframework.context.annotation.Bean; | |
| 9 | +import org.springframework.context.annotation.Configuration; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Metrics 配置类 | |
| 13 | + * | |
| 14 | + * @author 芋道源码 | |
| 15 | + */ | |
| 16 | +@Configuration | |
| 17 | +@ConditionalOnClass({MeterRegistryCustomizer.class}) | |
| 18 | +@ConditionalOnProperty(prefix = "yudao.metrics", value = "enable", matchIfMissing = true) // 允许使用 yudao.metrics.enable=false 禁用 Metrics | |
| 19 | +public class YudaoMetricsAutoConfiguration { | |
| 20 | + | |
| 21 | + @Bean | |
| 22 | + public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags( | |
| 23 | + @Value("${spring.application.name}") String applicationName) { | |
| 24 | + return registry -> registry.config().commonTags("application", applicationName); | |
| 25 | + } | |
| 26 | + | |
| 27 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-monitor/src/main/resources/META-INF/spring.factories
| 1 | 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ |
| 2 | - cn.iocoder.yudao.framework.tracer.config.YudaoTracerAutoConfiguration | |
| 2 | + cn.iocoder.yudao.framework.tracer.config.YudaoTracerAutoConfiguration,\ | |
| 3 | + cn.iocoder.yudao.framework.tracer.config.YudaoMetricsAutoConfiguration | ... | ... |