diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java index 63abe28..8b02569 100644 --- a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java +++ b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java @@ -16,9 +16,13 @@ public class CommonFilter implements Filter { public static String TOTAL_REQUST = "TOTAL_REQUEST"; public static String FAIL_REQUST = "FAIL_REQUEST"; + public static String FAIL4XX_REQUST = "FAIL4XX_REQUEST"; + public static String FAIL5XX_REQUST = "FAIL5XX_REQUEST"; public static String OK_REQUST = "OK_REQUEST"; private static int totalCount = 0; private static int failCount = 0; + private static int count4xx=0; + private static int count5xx=0; private static int okCount=0; private static int interval = 1440; // 24 hour private static HashMap EndpointCount = new HashMap(); @@ -40,6 +44,13 @@ public int getFailCount() { public int getOkCount() { return this.okCount; } + public int getCount4xx() { + return count4xx; + } + public int getCount5xx() { + return count5xx; + } + public HashMap getEndpointMap() { return this.EndpointCount; } @@ -60,6 +71,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha if (currentTime - preciousTime > gapMilliseconds) { //reset every 1 minutes totalCount = 0; failCount = 0; + count4xx=0; + count5xx=0; okCount=0; preciousTime = currentTime; EndpointCount.clear(); @@ -73,6 +86,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha } else { obj.put(TOTAL_REQUST, 0); obj.put(FAIL_REQUST, 0); + obj.put(FAIL4XX_REQUST, 0); + obj.put(FAIL5XX_REQUST, 0); obj.put(OK_REQUST, 0); obj.put(END_POINT, endpoint); } @@ -86,13 +101,25 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha // System.out.println("--response:"+response); if (resp.getStatus() != 200) { failCount++; + count5xx=failCount-count4xx; obj.put(FAIL_REQUST, (int) obj.get(FAIL_REQUST) + 1); + obj.put(FAIL5XX_REQUST, (int) obj.get(FAIL_REQUST)-(int) obj.get(FAIL4XX_REQUST)); + } + if (resp.getStatus() < 500 & resp.getStatus() > 399) { + count4xx++; + count5xx=failCount-count4xx; + obj.put(FAIL4XX_REQUST, (int) obj.get(FAIL4XX_REQUST) + 1); + obj.put(FAIL5XX_REQUST, (int) obj.get(FAIL_REQUST)-(int) obj.get(FAIL4XX_REQUST)); } } catch (Exception e) { failCount++; + count5xx=failCount-count4xx; obj.put(FAIL_REQUST, (int) obj.get(FAIL_REQUST) + 1); + obj.put(FAIL5XX_REQUST, (int) obj.get(FAIL_REQUST)-(int) obj.get(FAIL4XX_REQUST)); throw e; } + obj.put(OK_REQUST, (int) obj.get(TOTAL_REQUST) - (int) obj.get(FAIL_REQUST)); + okCount=totalCount-failCount; // update map EndpointCount.put(endpoint, obj); } else { diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java index 61e14a5..7ae2a28 100644 --- a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java @@ -8,36 +8,36 @@ @Slf4j public class MonitorInfo { - private int status; - private String msg; - private DataInfo data; + private int status; + private String msg; + private DataInfo data; - public int getStatus() { - return this.status; - } + public int getStatus() { + return this.status; + } - public MonitorInfo setStatus(int status) { - this.status = status; - return this; - } + public MonitorInfo setStatus(int status) { + this.status = status; + return this; + } - public String getMsg() { - return this.msg; - } + public String getMsg() { + return this.msg; + } - public MonitorInfo setMsg(String msg) { - this.msg = msg; - return this; - } + public MonitorInfo setMsg(String msg) { + this.msg = msg; + return this; + } - public DataInfo getDataInfo() { - return this.data; - } + public DataInfo getDataInfo() { + return this.data; + } - public MonitorInfo setDataInfo(DataInfo data) { - this.data = data; - return this; - } + public MonitorInfo setDataInfo(DataInfo data) { + this.data = data; + return this; + } // public MonitorInfo ToProtoEntity() { // Protocol.MonitorInfo.Builder builder = Protocol.MonitorInfo.newBuilder(); @@ -158,382 +158,444 @@ public MonitorInfo setDataInfo(DataInfo data) { // } - public static class DataInfo { - private int interval; - private NetInfo net; - - public int getInterval() { - return this.interval; - } - - public DataInfo setInterval(int interval) { - this.interval = interval; - return this; - } - public NetInfo getNetInfo() { - return this.net; - } - - public DataInfo setNetInfo(NetInfo net) { - this.net = net; - return this; - } - - // network monitor information - public static class NetInfo { - private int errorProtoCount; - private ApiInfo api; - private int connectionCount; - private int validConnectionCount; - private long TCPInTraffic; - private long TCPOutTraffic; - private int disconnectionCount; - private List disconnectionDetail = new ArrayList<>(); - private long UDPInTraffic; - private long UDPOutTraffic; - private LatencyInfo latency; - - public int getErrorProtoCount() { - return this.errorProtoCount; - } - - public NetInfo setErrorProtoCount(int errorProtoCount) { - this.errorProtoCount = errorProtoCount; - return this; - } - - public ApiInfo getApi() { - return this.api; - } - - public NetInfo setApi(ApiInfo api) { - this.api = api; - return this; - } - - public int getConnectionCount() { - return this.connectionCount; - } - - public NetInfo setConnectionCount(int connectionCount) { - this.connectionCount = connectionCount; - return this; - } - - public int getValidConnectionCount() { - return this.validConnectionCount; - } - - public NetInfo setValidConnectionCount(int validConnectionCount) { - this.validConnectionCount = validConnectionCount; - return this; - } - - public long getTCPInTraffic() { - return this.TCPInTraffic; - } - - public NetInfo setTCPInTraffic(long TCPInTraffic) { - this.TCPInTraffic = TCPInTraffic; - return this; - } - - public long getTCPOutTraffic() { - return this.TCPOutTraffic; - } - - public NetInfo setTCPOutTraffic(long TCPOutTraffic) { - this.TCPOutTraffic = TCPOutTraffic; - return this; - } - - public int getDisconnectionCount() { - return this.disconnectionCount; - } - - public NetInfo setDisconnectionCount(int disconnectionCount) { - this.disconnectionCount = disconnectionCount; - return this; - } - - public List getDisconnectionDetail() { - return this.disconnectionDetail; - } - - public NetInfo setDisconnectionDetail(List disconnectionDetail) { - this.disconnectionDetail = disconnectionDetail; - return this; - } - - public long getUDPInTraffic() { - return this.UDPInTraffic; - } - - public NetInfo setUDPInTraffic(long UDPInTraffic) { - this.UDPInTraffic = UDPInTraffic; - return this; - } - - public long getUDPOutTraffic() { - return this.UDPOutTraffic; - } + public static class DataInfo { + private int interval; + private NetInfo net; - public NetInfo setUDPOutTraffic(long UDPOutTraffic) { - this.UDPOutTraffic = UDPOutTraffic; - return this; - } - - public LatencyInfo getLatency() { - return this.latency; - } - - public NetInfo setLatency(LatencyInfo latency) { - this.latency = latency; - return this; - } - - // API monitor information - public static class ApiInfo { - private int totalCount; - private int totalFailCount; - private List detail = new ArrayList<>(); - - public int getTotalCount() { - return this.totalCount; - } - - public ApiInfo setTotalCount(int totalCount) { - this.totalCount = totalCount; - return this; - } - - public int getTotalFailCount() { - return this.totalFailCount; - } - - public ApiInfo setTotalFailCount(int totalFailCount) { - this.totalFailCount = totalFailCount; - return this; + public int getInterval() { + return this.interval; } - public List getApiDetailInfo() { - return this.detail; - } - - public ApiInfo setApiDetailInfo(List detail) { - this.detail = detail; - return this; - } - - public static class ApiDetailInfo { - private String name; - private int count; - private int failCount; - - public String getName() { - return this.name; - } - - public ApiDetailInfo setName(String name) { - this.name = name; + public DataInfo setInterval(int interval) { + this.interval = interval; return this; - } - - public int getCount() { - return this.count; - } - - public ApiDetailInfo setCount(int count) { - this.count = count; - return this; - } - - public int getFailCount() { - return this.failCount; - } - - public ApiDetailInfo setFailCount(int failCount) { - this.failCount = failCount; - return this; - } - } - } - - // disconnection monitor information - public static class DisconnectionDetailInfo { - private String reason; - private int count; - - public String getReason() { - return this.reason; } - public DisconnectionDetailInfo setReason(String reason) { - this.reason = reason; - return this; - } - - public int getCount() { - return this.count; - } - - public DisconnectionDetailInfo setCount(int count) { - this.count = count; - return this; - } - - } - - // latency monitor information - public static class LatencyInfo { - private int top99; - private int top95; - private int totalCount; - private int delay1S; - private int delay2S; - private int delay3S; - private List detail = new ArrayList<>(); - - public int getTop99() { - return this.top99; + public NetInfo getNetInfo() { + return this.net; } - public LatencyInfo setTop99(int top99) { - this.top99 = top99; - return this; - } - - public int getTop95() { - return this.top95; - } - - public LatencyInfo setTop95(int top95) { - this.top95 = top95; - return this; - } - - public int getTotalCount() { - return this.totalCount; - } - - public LatencyInfo setTotalCount(int totalCount) { - this.totalCount = totalCount; - return this; - } - - public int getDelay1S() { - return this.delay1S; - } - - public LatencyInfo setDelay1S(int delay1S) { - this.delay1S = delay1S; - return this; - } - - public int getDelay2S() { - return this.delay2S; - } - - public LatencyInfo setDelay2S(int delay2S) { - this.delay2S = delay2S; - return this; - } - - public int getDelay3S() { - return this.delay3S; - } - - public LatencyInfo setDelay3S(int delay3S) { - this.delay3S = delay3S; - return this; + public DataInfo setNetInfo(NetInfo net) { + this.net = net; + return this; } - public List getLatencyDetailInfo() { - return this.detail; - } + // network monitor information + public static class NetInfo { + private int errorProtoCount; + private ApiInfo api; + private int connectionCount; + private int validConnectionCount; + private long TCPInTraffic; + private long TCPOutTraffic; + private int disconnectionCount; + private List disconnectionDetail = new ArrayList<>(); + private long UDPInTraffic; + private long UDPOutTraffic; + private LatencyInfo latency; + + public int getErrorProtoCount() { + return this.errorProtoCount; + } + + public NetInfo setErrorProtoCount(int errorProtoCount) { + this.errorProtoCount = errorProtoCount; + return this; + } + + public ApiInfo getApi() { + return this.api; + } + + public NetInfo setApi(ApiInfo api) { + this.api = api; + return this; + } + + public int getConnectionCount() { + return this.connectionCount; + } + + public NetInfo setConnectionCount(int connectionCount) { + this.connectionCount = connectionCount; + return this; + } + + public int getValidConnectionCount() { + return this.validConnectionCount; + } + + public NetInfo setValidConnectionCount(int validConnectionCount) { + this.validConnectionCount = validConnectionCount; + return this; + } + + public long getTCPInTraffic() { + return this.TCPInTraffic; + } + + public NetInfo setTCPInTraffic(long TCPInTraffic) { + this.TCPInTraffic = TCPInTraffic; + return this; + } + + public long getTCPOutTraffic() { + return this.TCPOutTraffic; + } + + public NetInfo setTCPOutTraffic(long TCPOutTraffic) { + this.TCPOutTraffic = TCPOutTraffic; + return this; + } + + public int getDisconnectionCount() { + return this.disconnectionCount; + } + + public NetInfo setDisconnectionCount(int disconnectionCount) { + this.disconnectionCount = disconnectionCount; + return this; + } + + public List getDisconnectionDetail() { + return this.disconnectionDetail; + } + + public NetInfo setDisconnectionDetail(List disconnectionDetail) { + this.disconnectionDetail = disconnectionDetail; + return this; + } + + public long getUDPInTraffic() { + return this.UDPInTraffic; + } + + public NetInfo setUDPInTraffic(long UDPInTraffic) { + this.UDPInTraffic = UDPInTraffic; + return this; + } + + public long getUDPOutTraffic() { + return this.UDPOutTraffic; + } + + public NetInfo setUDPOutTraffic(long UDPOutTraffic) { + this.UDPOutTraffic = UDPOutTraffic; + return this; + } + + public LatencyInfo getLatency() { + return this.latency; + } + + public NetInfo setLatency(LatencyInfo latency) { + this.latency = latency; + return this; + } + + // API monitor information + public static class ApiInfo { + private int totalCount; + private int totalFailCount; + private int totalCount2xx; + private int totalCount4xx; + private int totalCount5xx; + + private List detail = new ArrayList<>(); + + public int getTotalCount() { + return this.totalCount; + } + + public ApiInfo setTotalCount(int totalCount) { + this.totalCount = totalCount; + return this; + } + + public int getTotalFailCount() { + return this.totalFailCount; + } + + public ApiInfo setTotalFailCount(int totalFailCount) { + this.totalFailCount = totalFailCount; + return this; + } + + public int getTotalCount2xx() { + return this.totalCount2xx; + } + + public ApiInfo setTotalCount2xx(int totalCount2xx) { + this.totalCount2xx = totalCount2xx; + return this; + } + + public int getTotalCount4xx() { + return this.totalCount4xx; + } + + public ApiInfo setTotalCount4xx(int totalCount4xx) { + this.totalCount4xx = totalCount4xx; + return this; + } + + public int getTotalCount5xx() { + return this.totalCount5xx; + } + + public ApiInfo setTotalCount5xx(int totalCount5xx) { + this.totalCount5xx = totalCount5xx; + return this; + } + + public List getApiDetailInfo() { + return this.detail; + } + + public ApiInfo setApiDetailInfo(List detail) { + this.detail = detail; + return this; + } + + public static class ApiDetailInfo { + private String name; + private int count; + private int failCount; + private int count4xx; + private int count5xx; + private int count2xx; + + + public String getName() { + return this.name; + } + + public ApiDetailInfo setName(String name) { + this.name = name; + return this; + } + + public int getCount() { + return this.count; + } + + public ApiDetailInfo setCount(int count) { + this.count = count; + return this; + } + + public int getFailCount() { + return this.failCount; + } + + public ApiDetailInfo setFailCount(int failCount) { + this.failCount = failCount; + return this; + } + + public int getCount4xx() { + return this.count4xx; + } + + public ApiDetailInfo setCount4xx(int count4xx) { + this.count4xx = count4xx; + return this; + } + + public int getCount5xx() { + return this.count5xx; + } + + public ApiDetailInfo setCount5xx(int count5xx) { + this.count5xx = count5xx; + return this; + } + public int getCount2xx() { + return this.count2xx; + } + + public ApiDetailInfo setCount2xx(int count2xx) { + this.count2xx = count2xx; + return this; + } + } + } + + // disconnection monitor information + public static class DisconnectionDetailInfo { + private String reason; + private int count; + + public String getReason() { + return this.reason; + } + + public DisconnectionDetailInfo setReason(String reason) { + this.reason = reason; + return this; + } + + public int getCount() { + return this.count; + } + + public DisconnectionDetailInfo setCount(int count) { + this.count = count; + return this; + } + + } + + // latency monitor information + public static class LatencyInfo { + private int top99; + private int top95; + private int totalCount; + private int delay1S; + private int delay2S; + private int delay3S; + private List detail = new ArrayList<>(); + + public int getTop99() { + return this.top99; + } + + public LatencyInfo setTop99(int top99) { + this.top99 = top99; + return this; + } + + public int getTop95() { + return this.top95; + } + + public LatencyInfo setTop95(int top95) { + this.top95 = top95; + return this; + } + + public int getTotalCount() { + return this.totalCount; + } + + public LatencyInfo setTotalCount(int totalCount) { + this.totalCount = totalCount; + return this; + } + + public int getDelay1S() { + return this.delay1S; + } + + public LatencyInfo setDelay1S(int delay1S) { + this.delay1S = delay1S; + return this; + } + + public int getDelay2S() { + return this.delay2S; + } + + public LatencyInfo setDelay2S(int delay2S) { + this.delay2S = delay2S; + return this; + } + + public int getDelay3S() { + return this.delay3S; + } + + public LatencyInfo setDelay3S(int delay3S) { + this.delay3S = delay3S; + return this; + } + + public List getLatencyDetailInfo() { + return this.detail; + } + + public LatencyInfo setLatencyDetailInfo(List detail) { + this.detail = detail; + return this; + } + + public static class LatencyDetailInfo { + private String witness; + private int top99; + private int top95; + private int count; + private int delay1S; + private int delay2S; + private int delay3S; + + public String getWitness() { + return this.witness; + } + + public LatencyDetailInfo setWitness(String witness) { + this.witness = witness; + return this; + } + + public int getTop99() { + return this.top99; + } + + public LatencyDetailInfo setTop99(int top99) { + this.top99 = top99; + return this; + } + + public int getTop95() { + return this.top95; + } + + public LatencyDetailInfo setTop95(int top95) { + this.top95 = top95; + return this; + } + + public int getCount() { + return this.count; + } + + public LatencyDetailInfo setCount(int count) { + this.count = count; + return this; + } + + public int getDelay1S() { + return this.delay1S; + } + + public LatencyDetailInfo setDelay1S(int delay1S) { + this.delay1S = delay1S; + return this; + } + + public int getDelay2S() { + return this.delay2S; + } + + public LatencyDetailInfo setDelay2S(int delay2S) { + this.delay2S = delay2S; + return this; + } + + public int getDelay3S() { + return this.delay3S; + } + + public LatencyDetailInfo setDelay3S(int delay3S) { + this.delay3S = delay3S; + return this; + } + + } + } - public LatencyInfo setLatencyDetailInfo(List detail) { - this.detail = detail; - return this; } - public static class LatencyDetailInfo { - private String witness; - private int top99; - private int top95; - private int count; - private int delay1S; - private int delay2S; - private int delay3S; - - public String getWitness() { - return this.witness; - } - - public LatencyDetailInfo setWitness(String witness) { - this.witness = witness; - return this; - } - - public int getTop99() { - return this.top99; - } - - public LatencyDetailInfo setTop99(int top99) { - this.top99 = top99; - return this; - } - - public int getTop95() { - return this.top95; - } - - public LatencyDetailInfo setTop95(int top95) { - this.top95 = top95; - return this; - } - - public int getCount() { - return this.count; - } - - public LatencyDetailInfo setCount(int count) { - this.count = count; - return this; - } - - public int getDelay1S() { - return this.delay1S; - } - - public LatencyDetailInfo setDelay1S(int delay1S) { - this.delay1S = delay1S; - return this; - } - - public int getDelay2S() { - return this.delay2S; - } - - public LatencyDetailInfo setDelay2S(int delay2S) { - this.delay2S = delay2S; - return this; - } - - public int getDelay3S() { - return this.delay3S; - } - - public LatencyDetailInfo setDelay3S(int delay3S) { - this.delay3S = delay3S; - return this; - } - - } - } } - - - } } diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java index 8dfeee5..ec8929e 100644 --- a/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java @@ -37,7 +37,10 @@ public void setNetInfo(MonitorInfo.DataInfo data) { MonitorInfo.DataInfo.NetInfo.ApiInfo apiInfo = new MonitorInfo.DataInfo.NetInfo.ApiInfo(); CommonFilter commonFilter=new CommonFilter(); apiInfo.setTotalCount(commonFilter.getInstance().getTotalCount()); + apiInfo.setTotalCount2xx(commonFilter.getInstance().getOkCount()); apiInfo.setTotalFailCount(commonFilter.getInstance().getFailCount()); + apiInfo.setTotalCount4xx(commonFilter.getInstance().getCount4xx()); + apiInfo.setTotalCount5xx(commonFilter.getInstance().getCount5xx()); List apiDetails = new ArrayList<>(); for(Map.Entry entry: commonFilter.getInstance().getEndpointMap().entrySet()){ MonitorInfo.DataInfo.NetInfo.ApiInfo.ApiDetailInfo apiDetail = @@ -45,6 +48,9 @@ public void setNetInfo(MonitorInfo.DataInfo data) { apiDetail.setName(entry.getKey()); apiDetail.setCount((int)entry.getValue().get(CommonFilter.TOTAL_REQUST)); apiDetail.setFailCount((int)entry.getValue().get(CommonFilter.FAIL_REQUST)); + apiDetail.setCount2xx((int)entry.getValue().get(CommonFilter.OK_REQUST)); + apiDetail.setCount4xx((int)entry.getValue().get(CommonFilter.FAIL4XX_REQUST)); + apiDetail.setCount5xx((int)entry.getValue().get(CommonFilter.FAIL5XX_REQUST)); apiDetails.add(apiDetail); } apiInfo.setApiDetailInfo(apiDetails);