Skip to content

Commit

Permalink
Merge pull request #25 from tronprotocol/develop-alberto
Browse files Browse the repository at this point in the history
add 2xx 4xx 5xx
  • Loading branch information
DorianRust authored Feb 21, 2020
2 parents 5cc0115 + 7edeef9 commit 64d5e74
Show file tree
Hide file tree
Showing 3 changed files with 482 additions and 387 deletions.
27 changes: 27 additions & 0 deletions src/main/java/org/tron/trongeventquery/filter/CommonFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, JSONObject> EndpointCount = new HashMap<String, JSONObject>();
Expand All @@ -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<String, JSONObject> getEndpointMap() {
return this.EndpointCount;
}
Expand All @@ -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();
Expand All @@ -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);
}
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 64d5e74

Please sign in to comment.