- 后端:增加自定义埋点测试

This commit is contained in:
YunaiV 2019-05-21 16:21:19 +08:00
parent a64a0e3887
commit 8240a0dc36
2 changed files with 19 additions and 0 deletions

View File

@ -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

View File

@ -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<AdminAuthenticationBO> login(AdminAuthenticationDTO adminAuthenticationDTO) {
// 增加计数
METRICS_LOGIN_TOTAL.increment();
// 执行登陆
return success(adminService.authentication(adminAuthenticationDTO));
}