From 8240a0dc363f1e59ba9cd7b329173a3649e9e52c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 21 May 2019 16:21:19 +0800 Subject: [PATCH] =?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)); }