From f29d427fb1f5a359b7ef3b97d58a9f015055cdf9 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 20 May 2019 16:12:57 +0800 Subject: [PATCH 1/6] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E4=B8=8B=20Metrics=20=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/mall-spring-boot/pom.xml | 13 ++++++++++ .../metrics/MetricsAutoConfiguration.java | 24 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 3 ++- order/order-application/pom.xml | 11 +++++++-- pay/pay-application/pom.xml | 11 +++++++-- product/product-application/pom.xml | 10 ++++++++ promotion/promotion-application/pom.xml | 10 ++++++++ search/search-application/pom.xml | 10 ++++++++ system/system-application/pom.xml | 5 ---- .../config/MonitorConfiguration.java | 9 ------- .../mall/admin/api/bo/sms/PageSmsSignBO.java | 3 +-- .../admin/api/bo/sms/PageSmsTemplateBO.java | 2 +- user/user-application/pom.xml | 12 ++++++++++ .../src/main/resources/application.yaml | 8 +++++++ 14 files changed, 109 insertions(+), 22 deletions(-) create mode 100644 common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/metrics/MetricsAutoConfiguration.java delete mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/config/MonitorConfiguration.java 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 From 849c814c2c60c12ddfce3e6824307cb141fff880 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 20 May 2019 17:20:46 +0800 Subject: [PATCH 2/6] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E4=B8=8B=20Metrics=20=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-test.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/system/system-application/src/main/resources/application-test.yaml b/system/system-application/src/main/resources/application-test.yaml index c7ab7fb7c..58f89a7cc 100644 --- a/system/system-application/src/main/resources/application-test.yaml +++ b/system/system-application/src/main/resources/application-test.yaml @@ -6,13 +6,13 @@ spring: url: http://127.0.0.1:18097 -management: - endpoints: - web: - exposure: - include: "*" - server: - port: 19083 # 配置独立端口。而该端口,不使用 nginx 对外暴露,从而不配置安全认证。也就是说,内网环境可访问,外网环境不可访问。当然,这么做的前提是,认为内网安全。 +#management: +# endpoints: +# web: +# exposure: +# include: "*" +# server: +# port: 19083 # 配置独立端口。而该端口,不使用 nginx 对外暴露,从而不配置安全认证。也就是说,内网环境可访问,外网环境不可访问。当然,这么做的前提是,认为内网安全。 swagger: enable: true # 暂时不去掉 From 1aa630e3c36edc363f70c9b747c02fb6ccc7910e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 20 May 2019 20:36:18 +0800 Subject: [PATCH 3/6] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E4=B8=8B=20Metrics=20=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yaml | 8 ++++++++ pay/pay-application/src/main/resources/application.yaml | 8 ++++++++ .../src/main/resources/application.yaml | 9 +++++++++ .../src/main/resources/application.yaml | 9 +++++++++ 4 files changed, 34 insertions(+) diff --git a/order/order-application/src/main/resources/application.yaml b/order/order-application/src/main/resources/application.yaml index 827377e97..f8614c729 100644 --- a/order/order-application/src/main/resources/application.yaml +++ b/order/order-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 diff --git a/pay/pay-application/src/main/resources/application.yaml b/pay/pay-application/src/main/resources/application.yaml index fec2024fe..3e2704368 100644 --- a/pay/pay-application/src/main/resources/application.yaml +++ b/pay/pay-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 diff --git a/promotion/promotion-application/src/main/resources/application.yaml b/promotion/promotion-application/src/main/resources/application.yaml index 5b2be8800..d388f4a8f 100644 --- a/promotion/promotion-application/src/main/resources/application.yaml +++ b/promotion/promotion-application/src/main/resources/application.yaml @@ -18,3 +18,12 @@ server: swagger: enable: false + + +management: + endpoints: + web: + exposure: + include: health,info,env,metrics,prometheus + metrics: + enabled: true diff --git a/search/search-application/src/main/resources/application.yaml b/search/search-application/src/main/resources/application.yaml index 8304ceb64..9f54ec3e5 100644 --- a/search/search-application/src/main/resources/application.yaml +++ b/search/search-application/src/main/resources/application.yaml @@ -18,3 +18,12 @@ server: swagger: enable: false + + +management: + endpoints: + web: + exposure: + include: health,info,env,metrics,prometheus + metrics: + enabled: true From 4eeabe7605f6e2076ae4bfb86499641cbeec951a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 20 May 2019 22:50:41 +0800 Subject: [PATCH 4/6] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20Prometheus=20=E5=92=8C=20Grafana=20=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 132640a15..c0f9f5940 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,12 @@ * 地址:http://skywalking-ui.shop.iocoder.cn:18099 * 管理员账号:admin / admin +**Grafana UI** + +* 地址:http://grafana.shop.iocoder.cn:18099 +* 演示账号:yudaoyuanma / yudaoyuanma +* 用于展示 Prometheus 收集的 Metrics 指标数据。 + **Dubbo Admin** * 地址:http://dubbo-admin.shop.iocoder.cn:18099 @@ -74,7 +80,8 @@ **Sentinel Console** -TODO +* 地址:http://sentinel.shop.iocoder.cn:18099 +* 账号:sentinel / sentinel **XXL-Job Console** @@ -139,7 +146,6 @@ TODO 此处应有一个架构图的装逼 JPG 图。 | [Elasticsearch](https://www.elastic.co/cn/) | 分布式搜索引擎 | 6.7.1 | | [Dubbo](http://dubbo.apache.org/) | 分布式 RPC 服务框架 | 2.7.1 | | [RocketMQ](http://dubbo.apache.org/) | 消息中间件 | 4.3.2 | -| [SkyWalking](http://skywalking.apache.org/) | 分布式应用追踪系统 | 6.0.0 | | [Seata](https://github.com/seata/seata) | 分布式事务中间件 | 0.5.1 | | [Zookeeper](http://zookeeper.apache.org/) | 分布式系统协调 | 3.4.9 作为注册中心 | | [XXL-Job](http://www.xuxueli.com/xxl-job/) | 分布式任务调度平台 | 2.0.1 | @@ -170,6 +176,21 @@ TODO 此处应有一个架构图的装逼 JPG 图。 | [React](https://reactjs.org/) | JavaScript 框架 | 16.7.0 | | [Ant Design](https://ant.design/docs/react/introduce-cn) | React UI 组件库 | 3.13.0 | +### 监控 + +一般来说,监控会有三种方式: + +* 1、Tracing ,我们采用 Apache SkyWalking +* 2、Logging ,我们采用 ELK +* 3、Metrics ,我们采用 Prometheus + +| 框架 | 说明 | 版本 | +| --- | --- | --- | +| [SkyWalking](http://skywalking.apache.org/) | 分布式应用追踪系统 | 6.0.0 | +| [Prometheus](https://prometheus.io/) | 服务监控体系 | 2.9.2 | +| [Alertmanager](https://prometheus.io/docs/alerting/alertmanager/) | 告警管理器 | 0.17.0 | +| [Grafana](https://grafana.com/) | 仪表盘和图形编辑器 | 0.17.0 | + ### 其它 * Jenkins 持续集成 From a64a0e3887b6e0950ce3a7f99d8038d7550cced1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 21 May 2019 15:33:35 +0800 Subject: [PATCH 5/6] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9Aproduct=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=A2=9E=E5=8A=A0=20metrics=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalExceptionHandler.java | 58 ------------------- .../src/main/resources/application.yaml | 9 +++ 2 files changed, 9 insertions(+), 58 deletions(-) delete mode 100644 common/common-framework/src/main/java/cn/iocoder/common/framework/exception/GlobalExceptionHandler.java diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/exception/GlobalExceptionHandler.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/exception/GlobalExceptionHandler.java deleted file mode 100644 index f49d1872b..000000000 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/exception/GlobalExceptionHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.common.framework.exception; - -import cn.iocoder.common.framework.constant.SysErrorCodeEnum; -import cn.iocoder.common.framework.vo.CommonResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.MissingServletRequestParameterException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.ConstraintViolationException; - -@ControllerAdvice -public class GlobalExceptionHandler { - - private Logger logger = LoggerFactory.getLogger(getClass()); - - // 逻辑异常 - @ResponseBody - @ExceptionHandler(value = ServiceException.class) - public CommonResult serviceExceptionHandler(HttpServletRequest req, ServiceException ex) { - logger.debug("[serviceExceptionHandler]", ex); - return CommonResult.error(ex.getCode(), ex.getMessage()); - } - - // Spring MVC 参数不正确 - @ResponseBody - @ExceptionHandler(value = MissingServletRequestParameterException.class) - public CommonResult missingServletRequestParameterExceptionHandler(HttpServletRequest req, MissingServletRequestParameterException ex) { - logger.warn("[missingServletRequestParameterExceptionHandler]", ex); - return CommonResult.error(SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getCode(), SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getMessage() + ":" + ex.getMessage()); - } - - @ResponseBody - @ExceptionHandler(value = ConstraintViolationException.class) - public CommonResult constraintViolationExceptionHandler(HttpServletRequest req, ConstraintViolationException ex) { - logger.info("[constraintViolationExceptionHandler]", ex); - // TODO 芋艿,后续要想一个更好的方式。 - // 拼接详细报错 - StringBuilder detailMessage = new StringBuilder("\n\n详细错误如下:"); - ex.getConstraintViolations().forEach(constraintViolation -> detailMessage.append("\n").append(constraintViolation.getMessage())); - return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getMessage() - + detailMessage.toString()); - } - - @ResponseBody - @ExceptionHandler(value = Exception.class) - public CommonResult resultExceptionHandler(HttpServletRequest req, Exception e) { - logger.error("[resultExceptionHandler]", e); - // 返回 - return CommonResult.error(SysErrorCodeEnum.SYS_ERROR.getCode(), SysErrorCodeEnum.SYS_ERROR.getMessage()); - } - - // TODO 芋艿,应该还有其它的异常,需要进行翻译 - -} diff --git a/product/product-application/src/main/resources/application.yaml b/product/product-application/src/main/resources/application.yaml index e6c88ddad..759bb545a 100644 --- a/product/product-application/src/main/resources/application.yaml +++ b/product/product-application/src/main/resources/application.yaml @@ -18,3 +18,12 @@ server: swagger: enable: false + + +management: + endpoints: + web: + exposure: + include: health,info,env,metrics,prometheus + metrics: + enabled: true From 8240a0dc363f1e59ba9cd7b329173a3649e9e52c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 21 May 2019 16:21:19 +0800 Subject: [PATCH 6/6] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E5=9F=8B=E7=82=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boot/web/handler/GlobalExceptionHandler.java | 9 +++++++++ .../controller/admins/PassportController.java | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/handler/GlobalExceptionHandler.java b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/handler/GlobalExceptionHandler.java index b4d4b77bb..e61a9b957 100644 --- a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/handler/GlobalExceptionHandler.java +++ b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/handler/GlobalExceptionHandler.java @@ -10,6 +10,8 @@ import cn.iocoder.mall.admin.api.SystemLogService; import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO; import com.alibaba.fastjson.JSON; +import io.micrometer.core.instrument.Counter; +import io.micrometer.core.instrument.Metrics; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.dubbo.config.annotation.Reference; import org.slf4j.Logger; @@ -29,6 +31,11 @@ import java.util.Date; @ControllerAdvice public class GlobalExceptionHandler { + /** + * 异常总数 Metrics + */ + private static final Counter EXCEPTION_COUNTER = Metrics.counter("mall.exception.total"); + private Logger logger = LoggerFactory.getLogger(getClass()); @Value("${spring.application.name}") @@ -73,6 +80,8 @@ public class GlobalExceptionHandler { // 插入异常日志 ExceptionLogAddDTO exceptionLog = new ExceptionLogAddDTO(); try { + // 增加异常计数 metrics + EXCEPTION_COUNTER.increment(); // 初始化 exceptionLog initExceptionLog(exceptionLog, req, e); // 执行插入 exceptionLog diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java index 78a384d8b..461781566 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java @@ -5,6 +5,8 @@ import cn.iocoder.mall.admin.api.AdminService; import cn.iocoder.mall.admin.api.OAuth2Service; import cn.iocoder.mall.admin.api.bo.admin.AdminAuthenticationBO; import cn.iocoder.mall.admin.api.dto.admin.AdminAuthenticationDTO; +import io.micrometer.core.instrument.Counter; +import io.micrometer.core.instrument.Metrics; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.dubbo.config.annotation.Reference; @@ -19,6 +21,11 @@ import static cn.iocoder.common.framework.vo.CommonResult.success; @Api("Admin Passport 模块") public class PassportController { + /** + * 登陆总数 Metrics + */ + private static final Counter METRICS_LOGIN_TOTAL = Metrics.counter("mall.admin.passport.login.total"); + @Reference(validation = "true", version = "${dubbo.provider.OAuth2Service.version}") private OAuth2Service oauth2Service; @@ -28,6 +35,9 @@ public class PassportController { @PostMapping("/login") @ApiOperation(value = "手机号 + 密码登陆") public CommonResult login(AdminAuthenticationDTO adminAuthenticationDTO) { + // 增加计数 + METRICS_LOGIN_TOTAL.increment(); + // 执行登陆 return success(adminService.authentication(adminAuthenticationDTO)); }