Merge remote-tracking branch 'origin/master'

pull/1/head
sin 2019-05-21 17:06:27 +08:00
commit 44616d8e62
24 changed files with 201 additions and 89 deletions

View File

@ -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 持续集成

View File

@ -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 芋艿,应该还有其它的异常,需要进行翻译
}

View File

@ -60,6 +60,19 @@
<optional>true</optional>
</dependency>
<!-- 监控相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>

View File

@ -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<MeterRegistry> metricsCommonTags() {
return registry -> registry.config().commonTags("application", applicationName);
}
}

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

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

View File

@ -59,13 +59,20 @@
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- 测试相关 -->

View File

@ -18,3 +18,11 @@ server:
swagger:
enable: false
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true

View File

@ -66,13 +66,20 @@
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>

View File

@ -18,3 +18,11 @@ server:
swagger:
enable: false
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true

View File

@ -65,6 +65,16 @@
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -18,3 +18,12 @@ server:
swagger:
enable: false
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true

View File

@ -76,6 +76,16 @@
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -18,3 +18,12 @@ server:
swagger:
enable: false
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true

View File

@ -65,6 +65,16 @@
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -18,3 +18,12 @@ server:
swagger:
enable: false
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true

View File

@ -75,11 +75,6 @@
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.prometheus</groupId>-->
<!-- <artifactId>simpleclient_spring_boot</artifactId>-->
<!-- </dependency>-->
<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -1,9 +0,0 @@
package cn.iocoder.mall.admin.application.config;
import org.springframework.context.annotation.Configuration;
@Configuration
//@EnablePrometheusEndpoint
//@EnableSpringBootMetricsCollector
public class MonitorConfiguration {
}

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));
}

View File

@ -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 # 暂时不去掉

View File

@ -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 {
/**
*
*/

View File

@ -25,7 +25,7 @@ public class PageSmsTemplateBO {
@Data
@Accessors(chain = true)
public class Template {
public static class Template {
/**
*
*/

View File

@ -62,6 +62,18 @@
<artifactId>swagger-bootstrap-ui</artifactId>
</dependency>
<!-- 监控相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -18,3 +18,11 @@ server:
swagger:
enable: false
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true