From 69b43a3a8502d14039f544885ff037ef3f5b89e6 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 24 五月 2019 17:32:39 +0800 Subject: [PATCH] 增加接口监控报警,增加违规订单处理,增加接口请求时间大于2s的统计 --- utils/src/main/java/org/yeshi/utils/statistic/http/LocalhostAccessLogUtil.java | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/utils/src/main/java/org/yeshi/utils/statistic/http/LocalhostAccessLogUtil.java b/utils/src/main/java/org/yeshi/utils/statistic/http/LocalhostAccessLogUtil.java index 5a9b63a..73740f9 100644 --- a/utils/src/main/java/org/yeshi/utils/statistic/http/LocalhostAccessLogUtil.java +++ b/utils/src/main/java/org/yeshi/utils/statistic/http/LocalhostAccessLogUtil.java @@ -1,6 +1,11 @@ package org.yeshi.utils.statistic.http; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; +import java.util.Locale; public class LocalhostAccessLogUtil { @@ -14,7 +19,13 @@ try { HttpRequestInfo info = new HttpRequestInfo(); + info.setIp(content.split("- -")[0]); + content = content.split("- -")[1]; + + int start = content.indexOf("\""); + String time = content.substring(0, start).trim().replace("[", "").replace("]", ""); + info.setDate(parseDate(time)); content = content.substring(start, content.length()); start = content.indexOf("\"", 1); String url = content.substring(1, start); @@ -26,6 +37,7 @@ String[] sts = content.substring(start + 1, content.length()).trim().split(" "); info.setStateCode(Integer.parseInt(sts[0])); info.setTime(sts[1].trim().equalsIgnoreCase("-") ? Integer.MAX_VALUE : Integer.parseInt(sts[1])); + return info; } catch (Exception e) { } @@ -33,6 +45,17 @@ return null; } + private static Date parseDate(String timeDesc) { + DateFormat format = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z", Locale.US); + try { + Date date = format.parse(timeDesc); + return date; + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + /** * 姹傝姹傛椂闂寸殑骞冲潎鍊� * -- Gitblit v1.8.0