1:为日志查询添加请求内容的条件
2:将请求日志表分为配置请求记录表和日志请求记录表 3:更改redis数据同步到集群的策略
This commit is contained in:
@@ -17,7 +17,7 @@ public class SwaggerLog extends BaseEntity<SwaggerLog> {
|
||||
private String serverIp;
|
||||
private String traceCode;
|
||||
private String requestUri;
|
||||
|
||||
private String tableName;
|
||||
private String exception;// 界面的异常信息框
|
||||
|
||||
private Date beginDate; // 开始日期
|
||||
@@ -151,4 +151,12 @@ public class SwaggerLog extends BaseEntity<SwaggerLog> {
|
||||
this.requestUri = requestUri;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.nis.web.controller.sys;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -27,8 +28,16 @@ public class SysLogController extends BaseController {
|
||||
|
||||
@RequiresPermissions("sys:swaggerLogList:view")
|
||||
@RequestMapping(value = "swaggerLogList")
|
||||
public String swaggerLogList(SwaggerLog swaggerLog, HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
Page<SwaggerLog> page = swaggerLogService.findSwaggerLogPage(new Page<SwaggerLog>(request, response), swaggerLog);
|
||||
public String swaggerLogList(SwaggerLog swaggerLog, HttpServletRequest request, HttpServletResponse response,
|
||||
Model model) {
|
||||
if (swaggerLog.getOpAction() != null && swaggerLog.getOpAction() == 4) {
|
||||
swaggerLog.setTableName("services_log_request_log");
|
||||
} else {
|
||||
swaggerLog.setTableName("services_config_request_log");
|
||||
}
|
||||
swaggerLog.setRequestContent(StringEscapeUtils.unescapeHtml4(swaggerLog.getRequestContent()));
|
||||
Page<SwaggerLog> page = swaggerLogService.findSwaggerLogPage(new Page<SwaggerLog>(request, response),
|
||||
swaggerLog);
|
||||
model.addAttribute("page", page);
|
||||
return "/sys/swaggerLogList";
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import com.nis.domain.restful.ServicesRequestLogBean;
|
||||
public interface ServicesRequestLogDao {
|
||||
|
||||
int insert(ServicesRequestLog record);
|
||||
int insertConfigLog(ServicesRequestLog record);
|
||||
int insertLogLog(ServicesRequestLog record);
|
||||
|
||||
public void deleteById(Long id);
|
||||
|
||||
|
||||
@@ -176,4 +176,185 @@
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="insertConfigLog" parameterType="com.nis.domain.ServicesRequestLog">
|
||||
insert into SERVICES_CONFIG_REQUEST_LOG
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
||||
<if test="operator != null">
|
||||
OPERATOR,
|
||||
</if>
|
||||
<if test="version != null">
|
||||
VERSION,
|
||||
</if>
|
||||
<if test="opAction != null">
|
||||
OPACTION,
|
||||
</if>
|
||||
<if test="opTime != null">
|
||||
OPTIME,
|
||||
</if>
|
||||
<if test="requestContent != null">
|
||||
REQUEST_CONTENT,
|
||||
</if>
|
||||
<if test="requestTime != null">
|
||||
REQUEST_TIME,
|
||||
</if>
|
||||
<if test="consumerTime != null">
|
||||
CONSUMER_TIME,
|
||||
</if>
|
||||
<if test="requestIp != null">
|
||||
REQUEST_IP,
|
||||
</if>
|
||||
<if test="businessCode != null">
|
||||
BUSINESS_CODE,
|
||||
</if>
|
||||
<if test="exceptionInfo != null">
|
||||
EXCEPTION_INFO,
|
||||
</if>
|
||||
<if test="serverIp != null">
|
||||
SERVER_IP,
|
||||
</if>
|
||||
<if test="traceCode != null">
|
||||
TRACE_CODE,
|
||||
</if>
|
||||
<if test="requestURI != null">
|
||||
REQUEST_URI,
|
||||
</if>
|
||||
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
|
||||
<if test="operator != null">
|
||||
#{operator,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="version != null">
|
||||
#{version,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="opAction != null">
|
||||
#{opAction,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="opTime != null">
|
||||
#{opTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="requestContent != null">
|
||||
#{requestContent,jdbcType=CLOB},
|
||||
</if>
|
||||
<if test="requestTime != null">
|
||||
#{requestTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="consumerTime != null">
|
||||
#{consumerTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="requestIp != null">
|
||||
#{requestIp,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="businessCode != null">
|
||||
#{businessCode,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="exceptionInfo != null">
|
||||
#{exceptionInfo,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="serverIp != null">
|
||||
#{serverIp,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="traceCode != null">
|
||||
#{traceCode,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="requestURI != null">
|
||||
#{requestURI,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
||||
|
||||
|
||||
<insert id="insertLogLog" parameterType="com.nis.domain.ServicesRequestLog">
|
||||
insert into SERVICES_LOG_REQUEST_LOG
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
||||
<if test="operator != null">
|
||||
OPERATOR,
|
||||
</if>
|
||||
<if test="version != null">
|
||||
VERSION,
|
||||
</if>
|
||||
<if test="opAction != null">
|
||||
OPACTION,
|
||||
</if>
|
||||
<if test="opTime != null">
|
||||
OPTIME,
|
||||
</if>
|
||||
<if test="requestContent != null">
|
||||
REQUEST_CONTENT,
|
||||
</if>
|
||||
<if test="requestTime != null">
|
||||
REQUEST_TIME,
|
||||
</if>
|
||||
<if test="consumerTime != null">
|
||||
CONSUMER_TIME,
|
||||
</if>
|
||||
<if test="requestIp != null">
|
||||
REQUEST_IP,
|
||||
</if>
|
||||
<if test="businessCode != null">
|
||||
BUSINESS_CODE,
|
||||
</if>
|
||||
<if test="exceptionInfo != null">
|
||||
EXCEPTION_INFO,
|
||||
</if>
|
||||
<if test="serverIp != null">
|
||||
SERVER_IP,
|
||||
</if>
|
||||
<if test="traceCode != null">
|
||||
TRACE_CODE,
|
||||
</if>
|
||||
<if test="requestURI != null">
|
||||
REQUEST_URI,
|
||||
</if>
|
||||
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
|
||||
<if test="operator != null">
|
||||
#{operator,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="version != null">
|
||||
#{version,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="opAction != null">
|
||||
#{opAction,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="opTime != null">
|
||||
#{opTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="requestContent != null">
|
||||
#{requestContent,jdbcType=CLOB},
|
||||
</if>
|
||||
<if test="requestTime != null">
|
||||
#{requestTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="consumerTime != null">
|
||||
#{consumerTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="requestIp != null">
|
||||
#{requestIp,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="businessCode != null">
|
||||
#{businessCode,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="exceptionInfo != null">
|
||||
#{exceptionInfo,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="serverIp != null">
|
||||
#{serverIp,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="traceCode != null">
|
||||
#{traceCode,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="requestURI != null">
|
||||
#{requestURI,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -5,7 +5,7 @@
|
||||
<select id="findList" resultType="swaggerLog">
|
||||
SELECT
|
||||
a.*
|
||||
FROM services_request_log a
|
||||
FROM ${tableName} a
|
||||
WHERE a.request_time BETWEEN
|
||||
#{beginDate} AND #{endDate}
|
||||
|
||||
|
||||
@@ -51,8 +51,13 @@ public class ServicesRequestLogService {
|
||||
@Autowired
|
||||
public ServicesRequestLogDao servicesRequestLogDao;
|
||||
|
||||
private void saveLog(ServicesRequestLog log) {
|
||||
servicesRequestLogDao.insert(log);
|
||||
private void saveLog(ServicesRequestLog log, boolean isPzLog) {
|
||||
if (isPzLog) {
|
||||
servicesRequestLogDao.insertConfigLog(log);
|
||||
} else {
|
||||
servicesRequestLogDao.insertLogLog(log);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,8 +71,7 @@ public class ServicesRequestLogService {
|
||||
* @param queryString
|
||||
* request中的参数
|
||||
* @param contextPath
|
||||
* request中的参数
|
||||
* 响应
|
||||
* request中的参数 响应
|
||||
* @param operator
|
||||
* 操作人
|
||||
* @param version
|
||||
@@ -115,8 +119,8 @@ public class ServicesRequestLogService {
|
||||
} else {
|
||||
InetAddress ip = null;
|
||||
boolean bFindIP = false;
|
||||
Enumeration<NetworkInterface> netInterfaces=(Enumeration<NetworkInterface>)
|
||||
NetworkInterface.getNetworkInterfaces();
|
||||
Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
|
||||
.getNetworkInterfaces();
|
||||
while (netInterfaces.hasMoreElements()) {
|
||||
if (bFindIP) {
|
||||
break;
|
||||
@@ -125,7 +129,8 @@ public class ServicesRequestLogService {
|
||||
Enumeration<InetAddress> ips = ni.getInetAddresses();
|
||||
while (ips.hasMoreElements()) {
|
||||
ip = (InetAddress) ips.nextElement();
|
||||
if(ip.isSiteLocalAddress()&&!ip.isLoopbackAddress()&&ip.getHostAddress().indexOf(":")==-1){
|
||||
if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress()
|
||||
&& ip.getHostAddress().indexOf(":") == -1) {
|
||||
bFindIP = true;
|
||||
break;
|
||||
}
|
||||
@@ -173,9 +178,14 @@ public class ServicesRequestLogService {
|
||||
}
|
||||
|
||||
}
|
||||
this.saveLog(log);
|
||||
if (log.getRequestURI() == null || log.getRequestURI().toLowerCase().contains("service/log")) {
|
||||
this.saveLog(log, false);
|
||||
} else {
|
||||
this.saveLog(log, true);
|
||||
}
|
||||
logger.info("记录日志完成---");
|
||||
}
|
||||
|
||||
public boolean isWindows() {
|
||||
boolean isWindows = false;
|
||||
if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
|
||||
@@ -183,9 +193,10 @@ public class ServicesRequestLogService {
|
||||
}
|
||||
return isWindows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接从数据源获取connection保存日志的方法,用saveLog()方法就行 save(这里用一句话描述这个方法的作用)
|
||||
* (这里描述这个方法适用条件 – 可选)
|
||||
* 直接从数据源获取connection保存日志的方法,用saveLog()方法就行 save(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件
|
||||
* – 可选)
|
||||
*
|
||||
* @param data
|
||||
* @throws IllegalArgumentException
|
||||
|
||||
@@ -40,6 +40,8 @@ public class SyncRedisToCluster {
|
||||
// @Scheduled(cron = "${syncRedisToClusterCron}")
|
||||
public void syncRedisToCluster() {
|
||||
try {
|
||||
String rpopRedisList = rpopRedisList("SyncRedisToCluster");
|
||||
if (rpopRedisList != null) {//避免集群环境下同一秒钟所有的机器都执行这个定时任务
|
||||
// keys("EFFECTIVE_RULE*");
|
||||
// keys("OBSOLETE_RULE*");
|
||||
String clusterMaatVersionStr = jedisCluster.get("MAAT_VERSION");
|
||||
@@ -54,7 +56,8 @@ public class SyncRedisToCluster {
|
||||
} else if (redisMaatVersion > clusterMaatVersion) {// 获取增量的数据
|
||||
logger.info("redis集群中的MAAT_VERSION为小于配置库中的MAAT_VERSION,开始执行增量同步,score是{}-{}",
|
||||
clusterMaatVersion, +redisMaatVersion);
|
||||
syncData(clusterMaatVersion.doubleValue(), redisMaatVersion.doubleValue(), redisMaatVersionStr);
|
||||
syncData(clusterMaatVersion.doubleValue(), redisMaatVersion.doubleValue(),
|
||||
redisMaatVersionStr);
|
||||
} else {
|
||||
logger.info("redis集群中的MAAT_VERSION与配置库中的MAAT_VERSION相等,暂不执行配置同步操作");
|
||||
}
|
||||
@@ -65,12 +68,17 @@ public class SyncRedisToCluster {
|
||||
}
|
||||
} else {
|
||||
if (redisMaatVersionStr != null && !redisMaatVersionStr.trim().equals("")) {
|
||||
logger.info("redis配置库中的MAAT_VERSION为{},redis集群中的MAAT_VERSION为null,开始执行全量同步", redisMaatVersionStr);
|
||||
logger.info("redis配置库中的MAAT_VERSION为{},redis集群中的MAAT_VERSION为null,开始执行全量同步",
|
||||
redisMaatVersionStr);
|
||||
syncAllData(redisMaatVersionStr);
|
||||
} else {
|
||||
logger.info("redis配置库中和redis集群中的MAAT_VERSION都为null,暂时不执行全量同步");
|
||||
}
|
||||
}
|
||||
lpushRedisList("SyncRedisToCluster", "1");
|
||||
} else {
|
||||
logger.info("没有从rediscluster中获取到SyncRedisToCluster的值,暂时不执行数据同步!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("同步配置库配置到3A-redisCluster失败,失败原因:{}", ExceptionUtil.getExceptionMsg(e));
|
||||
}
|
||||
@@ -190,4 +198,29 @@ public class SyncRedisToCluster {
|
||||
logger.info("向redis集群同步数据成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储Redis队列,顺序存储
|
||||
*
|
||||
* @param key
|
||||
* redis键名
|
||||
* @param value
|
||||
* 键值
|
||||
*/
|
||||
public void lpushRedisList(String key, String value) {
|
||||
// LPUSH SyncRedisToCluster "1"
|
||||
jedisCluster.lpush(key, value);
|
||||
logger.info("向redis集群的{}中lpush了一个值{}", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除并获取列表最后一个元素
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public String rpopRedisList(String key) {
|
||||
// RPOP SyncRedisToCluster
|
||||
return jedisCluster.rpop(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,16 +42,17 @@
|
||||
</form:select>
|
||||
|
||||
|
||||
<label>请求内容:</label><input id="requestContent" name="requestContent" type="text" class="input-mini" value="<c:out value="${swaggerLog.requestContent}"></c:out>"/>
|
||||
<label>TRACECODE:</label><input id="traceCode" name="traceCode" type="text" maxlength="30" class="input-mini" value="${swaggerLog.traceCode}"/>
|
||||
<label>BUSINESSCODE:</label><input id="businessCode" name="businessCode" type="text" maxlength="30" class="input-mini" value="${swaggerLog.businessCode}"/>
|
||||
<label>异常信息:</label><input id="exceptionInfo" name="exceptionInfo" type="text" maxlength="500" class="input-mini" value="${swaggerLog.exceptionInfo}"/>
|
||||
<label>请求ip:</label><input id="requestIp" name="requestIp" type="text" maxlength="50" class="input-mini" value="${swaggerLog.requestIp}"/>
|
||||
<label>服务端ip:</label><input id="serverIp" name="serverIp" type="text" maxlength="50" class="input-mini" value="${swaggerLog.serverIp}"/>
|
||||
</div><div style="margin-top:8px;">
|
||||
<label>请求日期范围: </label><input id="beginDate" name="beginDate" type="text" readonly="readonly" maxlength="20" class="input-mini Wdate"
|
||||
value="<fmt:formatDate value="${swaggerLog.beginDate}" pattern="yyyy-MM-dd"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
|
||||
<label> -- </label><input id="endDate" name="endDate" type="text" readonly="readonly" maxlength="20" class="input-mini Wdate"
|
||||
value="<fmt:formatDate value="${swaggerLog.endDate}" pattern="yyyy-MM-dd"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
|
||||
<label>请求日期范围: </label><input id="beginDate" name="beginDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
|
||||
value="<fmt:formatDate value="${swaggerLog.beginDate}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
|
||||
<label> -- </label><input id="endDate" name="endDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
|
||||
value="<fmt:formatDate value="${swaggerLog.endDate}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
|
||||
<label for="exception">
|
||||
|
||||
<input id="exception" name="exception" type="checkbox" ${swaggerLog.exception eq '1'?' checked':''} value="1"/>只查询异常信息</label>
|
||||
|
||||
Reference in New Issue
Block a user