diff --git a/common/mall-spring-boot/pom.xml b/common/mall-spring-boot/pom.xml index b7e3aff98..41809e871 100644 --- a/common/mall-spring-boot/pom.xml +++ b/common/mall-spring-boot/pom.xml @@ -60,6 +60,19 @@ true + + + org.springframework.boot + spring-boot-actuator-autoconfigure + true + + + + io.micrometer + micrometer-registry-prometheus + true + + diff --git a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/metrics/MetricsAutoConfiguration.java b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/metrics/MetricsAutoConfiguration.java new file mode 100644 index 000000000..b5fe3f029 --- /dev/null +++ b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/metrics/MetricsAutoConfiguration.java @@ -0,0 +1,24 @@ +package cn.iocoder.mall.spring.boot.metrics; + +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; + +@Configuration +@ConditionalOnClass({MeterRegistryCustomizer.class}) +@ConditionalOnProperty(prefix = "management.metrics", value = "enable", matchIfMissing = true) // 允许使用 management.metrics.enable=false 禁用 Metrics +public class MetricsAutoConfiguration { + + @Value("${spring.application.name}") + private String applicationName; + + @Bean + MeterRegistryCustomizer metricsCommonTags() { + return registry -> registry.config().commonTags("application", applicationName); + } + +} diff --git a/common/mall-spring-boot/src/main/resources/META-INF/spring.factories b/common/mall-spring-boot/src/main/resources/META-INF/spring.factories index 771427063..8d7f6f54c 100644 --- a/common/mall-spring-boot/src/main/resources/META-INF/spring.factories +++ b/common/mall-spring-boot/src/main/resources/META-INF/spring.factories @@ -1,4 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ cn.iocoder.mall.spring.boot.web.AdminMVCAutoConfiguration, \ cn.iocoder.mall.spring.boot.web.UserMVCAutoConfiguration, \ - cn.iocoder.mall.spring.boot.swagger.SwaggerAutoConfiguration + cn.iocoder.mall.spring.boot.swagger.SwaggerAutoConfiguration, \ + cn.iocoder.mall.spring.boot.metrics.MetricsAutoConfiguration diff --git a/order/order-application/pom.xml b/order/order-application/pom.xml index cc0bcf65a..2e43a9ac1 100644 --- a/order/order-application/pom.xml +++ b/order/order-application/pom.xml @@ -59,13 +59,20 @@ de.codecentric spring-boot-admin-starter-client + + + org.springframework.cloud + spring-cloud-starter-alibaba-sentinel + + org.springframework.boot spring-boot-starter-actuator + - org.springframework.cloud - spring-cloud-starter-alibaba-sentinel + io.micrometer + micrometer-registry-prometheus diff --git a/pay/pay-application/pom.xml b/pay/pay-application/pom.xml index b65fe4b72..072c33613 100644 --- a/pay/pay-application/pom.xml +++ b/pay/pay-application/pom.xml @@ -66,13 +66,20 @@ de.codecentric spring-boot-admin-starter-client + + + org.springframework.cloud + spring-cloud-starter-alibaba-sentinel + + org.springframework.boot spring-boot-starter-actuator + - org.springframework.cloud - spring-cloud-starter-alibaba-sentinel + io.micrometer + micrometer-registry-prometheus diff --git a/product/product-application/pom.xml b/product/product-application/pom.xml index 0cab41c92..88cd820ad 100644 --- a/product/product-application/pom.xml +++ b/product/product-application/pom.xml @@ -65,6 +65,16 @@ spring-cloud-starter-alibaba-sentinel + + org.springframework.boot + spring-boot-starter-actuator + + + + io.micrometer + micrometer-registry-prometheus + + org.springframework.boot diff --git a/promotion/promotion-application/pom.xml b/promotion/promotion-application/pom.xml index ba80d881d..f398fafd6 100644 --- a/promotion/promotion-application/pom.xml +++ b/promotion/promotion-application/pom.xml @@ -76,6 +76,16 @@ spring-cloud-starter-alibaba-sentinel + + org.springframework.boot + spring-boot-starter-actuator + + + + io.micrometer + micrometer-registry-prometheus + + org.springframework.boot diff --git a/search/search-application/pom.xml b/search/search-application/pom.xml index acbefe1ae..10f2bfb9c 100644 --- a/search/search-application/pom.xml +++ b/search/search-application/pom.xml @@ -65,6 +65,16 @@ spring-cloud-starter-alibaba-sentinel + + org.springframework.boot + spring-boot-starter-actuator + + + + io.micrometer + micrometer-registry-prometheus + + org.springframework.boot diff --git a/system/system-application/pom.xml b/system/system-application/pom.xml index bff5c20f7..825316704 100644 --- a/system/system-application/pom.xml +++ b/system/system-application/pom.xml @@ -75,11 +75,6 @@ micrometer-registry-prometheus - - - - - org.springframework.boot diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/config/MonitorConfiguration.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/config/MonitorConfiguration.java deleted file mode 100644 index d63e5d4fe..000000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/config/MonitorConfiguration.java +++ /dev/null @@ -1,9 +0,0 @@ -package cn.iocoder.mall.admin.application.config; - -import org.springframework.context.annotation.Configuration; - -@Configuration -//@EnablePrometheusEndpoint -//@EnableSpringBootMetricsCollector -public class MonitorConfiguration { -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsSignBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsSignBO.java index 65409b84e..8d8eee9ea 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsSignBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsSignBO.java @@ -1,6 +1,5 @@ package cn.iocoder.mall.admin.api.bo.sms; -import com.baomidou.mybatisplus.annotation.TableId; import lombok.Data; import lombok.experimental.Accessors; @@ -28,7 +27,7 @@ public class PageSmsSignBO { @Data @Accessors(chain = true) - public class Sign { + public static class Sign { /** * 编号 */ diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsTemplateBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsTemplateBO.java index c67bbdf99..739e3edc2 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsTemplateBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsTemplateBO.java @@ -25,7 +25,7 @@ public class PageSmsTemplateBO { @Data @Accessors(chain = true) - public class Template { + public static class Template { /** * 编号 */ diff --git a/user/user-application/pom.xml b/user/user-application/pom.xml index 4edc53e4c..b92d394b3 100644 --- a/user/user-application/pom.xml +++ b/user/user-application/pom.xml @@ -62,6 +62,18 @@ swagger-bootstrap-ui + + + + org.springframework.boot + spring-boot-starter-actuator + + + + io.micrometer + micrometer-registry-prometheus + + org.springframework.boot diff --git a/user/user-application/src/main/resources/application.yaml b/user/user-application/src/main/resources/application.yaml index e8930c403..3745db650 100644 --- a/user/user-application/src/main/resources/application.yaml +++ b/user/user-application/src/main/resources/application.yaml @@ -18,3 +18,11 @@ server: swagger: enable: false + +management: + endpoints: + web: + exposure: + include: health,info,env,metrics,prometheus + metrics: + enabled: true