diff --git a/yudao-framework/yudao-spring-boot-starter-monitor/pom.xml b/yudao-framework/yudao-spring-boot-starter-monitor/pom.xml index 5c728353c..ebd1210c0 100644 --- a/yudao-framework/yudao-spring-boot-starter-monitor/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-monitor/pom.xml @@ -58,6 +58,12 @@ apm-toolkit-opentracing + + + io.micrometer + micrometer-registry-prometheus + + de.codecentric spring-boot-admin-starter-client diff --git a/yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoMetricsAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoMetricsAutoConfiguration.java new file mode 100644 index 000000000..cda0d2cb8 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoMetricsAutoConfiguration.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.framework.tracer.config; + +import io.micrometer.core.instrument.MeterRegistry; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Metrics 配置类 + * + * @author 芋道源码 + */ +@Configuration +@ConditionalOnClass({MeterRegistryCustomizer.class}) +@ConditionalOnProperty(prefix = "yudao.metrics", value = "enable", matchIfMissing = true) // 允许使用 yudao.metrics.enable=false 禁用 Metrics +public class YudaoMetricsAutoConfiguration { + + @Bean + public MeterRegistryCustomizer metricsCommonTags( + @Value("${spring.application.name}") String applicationName) { + return registry -> registry.config().commonTags("application", applicationName); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-monitor/src/main/resources/META-INF/spring.factories b/yudao-framework/yudao-spring-boot-starter-monitor/src/main/resources/META-INF/spring.factories index 6f4f606bb..9b69f01ea 100644 --- a/yudao-framework/yudao-spring-boot-starter-monitor/src/main/resources/META-INF/spring.factories +++ b/yudao-framework/yudao-spring-boot-starter-monitor/src/main/resources/META-INF/spring.factories @@ -1,2 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - cn.iocoder.yudao.framework.tracer.config.YudaoTracerAutoConfiguration + cn.iocoder.yudao.framework.tracer.config.YudaoTracerAutoConfiguration,\ + cn.iocoder.yudao.framework.tracer.config.YudaoMetricsAutoConfiguration