From b484f60367c77535cf0cdc79c0ca660b50aae8f9 Mon Sep 17 00:00:00 2001 From: zlt Date: Fri, 10 May 2019 00:11:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/central/SearchCenterApp.java | 1 + zlt-doc/sql/user-center.sql | 6 +++ .../filter/pre/RequestStatisticsFilter.java | 47 ++++++++++++------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/zlt-business/search-center/search-server/src/main/java/com/central/SearchCenterApp.java b/zlt-business/search-center/search-server/src/main/java/com/central/SearchCenterApp.java index ff91c04..cb59ea1 100644 --- a/zlt-business/search-center/search-server/src/main/java/com/central/SearchCenterApp.java +++ b/zlt-business/search-center/search-server/src/main/java/com/central/SearchCenterApp.java @@ -9,6 +9,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; /** * @author zlt + * @date 2019/5/1 */ @EnableLoginArgResolver @EnableDiscoveryClient diff --git a/zlt-doc/sql/user-center.sql b/zlt-doc/sql/user-center.sql index b155a85..a3abf70 100644 --- a/zlt-doc/sql/user-center.sql +++ b/zlt-doc/sql/user-center.sql @@ -132,6 +132,9 @@ INSERT INTO `sys_menu` VALUES (67, -1, '任务管理', '#!job', 'http://127.0.0. INSERT INTO `sys_menu` VALUES (68, 63, '应用吞吐量监控', '#!sentinel', 'http://127.0.0.1:6999', NULL, 'layui-icon-chart', 4, '2019-01-22 16:31:55', '2019-01-22 16:34:03', 1, 0); INSERT INTO `sys_menu` VALUES (69, 37, '配置中心', '#!nacos', 'http://127.0.0.1:8848/nacos', NULL, 'layui-icon-tabs', 1, '2019-01-23 14:06:10', '2019-01-23 14:06:10', 1, 0); INSERT INTO `sys_menu` VALUES (70, 63, 'APM监控', '#!apm', 'http://127.0.0.1:8080', null, 'layui-icon-engine', 5, '2019-02-27 10:31:55', '2019-02-27 10:31:55', 1, 0); +INSERT INTO `sys_menu` VALUES (71, -1, '搜索管理', 'javascript:;', '', NULL, 'layui-icon-set', 3, '2018-08-25 10:41:58', '2019-01-23 15:07:07', 1, 0); +INSERT INTO `sys_menu` VALUES (72, 71, '索引管理', '#!index', 'search/index_manager.html', NULL, 'layui-icon-template', 1, '2019-01-10 18:35:55', '2019-01-12 00:27:20', 1, 0); +INSERT INTO `sys_menu` VALUES (73, 71, '用户搜索', '#!userSearch', 'search/user_search.html', NULL, 'layui-icon-user', 2, '2019-01-10 18:35:55', '2019-01-12 00:27:20', 1, 0); -- ---------------------------- -- Table structure for sys_role_menu @@ -164,6 +167,9 @@ INSERT INTO `sys_role_menu` VALUES (1, 67); INSERT INTO `sys_role_menu` VALUES (1, 68); INSERT INTO `sys_role_menu` VALUES (1, 69); INSERT INTO `sys_role_menu` VALUES (1, 70); +INSERT INTO `sys_role_menu` VALUES (1, 71); +INSERT INTO `sys_role_menu` VALUES (1, 72); +INSERT INTO `sys_role_menu` VALUES (1, 73); INSERT INTO `sys_role_menu` VALUES (2, 2); INSERT INTO `sys_role_menu` VALUES (2, 3); INSERT INTO `sys_role_menu` VALUES (2, 4); diff --git a/zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/filter/pre/RequestStatisticsFilter.java b/zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/filter/pre/RequestStatisticsFilter.java index d79b5e1..bbeabb6 100644 --- a/zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/filter/pre/RequestStatisticsFilter.java +++ b/zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/filter/pre/RequestStatisticsFilter.java @@ -1,5 +1,6 @@ package com.central.gateway.filter.pre; +import cn.hutool.core.util.StrUtil; import com.central.log.monitor.PointUtil; import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.context.RequestContext; @@ -11,14 +12,16 @@ import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; /** - * 统计分析埋点过滤器 + * 请求统计分析埋点过滤器 * * @author zlt - * @date 2018/11/20 + * @date 2019/5/6 */ @Slf4j @Component public class RequestStatisticsFilter extends ZuulFilter { + private final static String UNKNOWN_STR = "unknown"; + @Override public String filterType() { return FilterConstants.PRE_TYPE; @@ -41,9 +44,10 @@ public class RequestStatisticsFilter extends ZuulFilter { UserAgent userAgent = UserAgent.parseUserAgentString(req.getHeader("User-Agent")); //埋点 - PointUtil.debug("0","request-statistics","ip="+this.getIpAddr(req) - +"&browser="+userAgent.getBrowser() - +"&operatingSystem="+userAgent.getOperatingSystem()); + PointUtil.debug("0","request-statistics", + "ip="+this.getIpAddr(req) + +"&browser="+userAgent.getBrowser() + +"&operatingSystem="+userAgent.getOperatingSystem()); return null; } @@ -52,21 +56,28 @@ public class RequestStatisticsFilter extends ZuulFilter { */ public String getIpAddr(HttpServletRequest request){ String ip = request.getHeader("X-Forwarded-For"); - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (isEmptyIP(ip)) { ip = request.getHeader("Proxy-Client-IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("WL-Proxy-Client-IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("HTTP_CLIENT_IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("HTTP_X_FORWARDED_FOR"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getRemoteAddr(); + if (isEmptyIP(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + if (isEmptyIP(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + if (isEmptyIP(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + if (isEmptyIP(ip)) { + ip = request.getRemoteAddr(); + } + } + } + } } return ip; } + + private boolean isEmptyIP(String ip) { + if (StrUtil.isEmpty(ip) || UNKNOWN_STR.equalsIgnoreCase(ip)) { + return true; + } + return false; + } } -- GitLab