gsd 9 months ago
parent
commit
bce3715fb0
  1. 2
      src/main/java/app/annotations/impl/CollectStatisticAspect.java
  2. 2
      src/main/java/app/annotations/interfaces/CollectStatistic.java
  3. 8
      src/main/java/app/entities/db/CollectableStatistic.java
  4. 21
      src/main/java/app/services/db/web/CollectStatisticFilter.java
  5. 10
      src/main/java/app/services/db/web/CollectStatisticService.java

2
src/main/java/app/annotations/impl/CollectStatisticAspect.java

@ -3,7 +3,7 @@ package app.annotations.impl;
import app.annotations.enums.CollectStages;
import app.annotations.interfaces.CollectStatistic;
import app.entities.db.CollectableStatistic;
import app.services.db.CollectStatisticService;
import app.services.db.web.CollectStatisticService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.aspectj.lang.JoinPoint;

2
src/main/java/app/annotations/interfaces/CollectStatistic.java

@ -14,5 +14,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CollectStatistic {
public CollectStages stage() default CollectStages.BEFORE;
CollectStages stage() default CollectStages.BEFORE;
}

8
src/main/java/app/entities/db/CollectableStatistic.java

@ -59,14 +59,6 @@ public class CollectableStatistic {
return Arrays.stream(rawCookieParams).filter(s -> s.contains(cookie_name + "=")).map(s -> s.split(cookie_name + "=")[1]).findFirst().orElse(null);
}
public boolean isServerRequest() {
return getClient_ip() != null && getClient_ip().equals("192.168.3.3") && getPath() != null && getPath().equals("/api/stats");
}
public boolean isIgnoreRule() {
return getPath() != null && getPath().equals("/api/stats") && getQuery() != null && !getQuery().contains("filter=servers");
}
public boolean isStatsRequests() {
return getPath().equals("/api/stats");
}

21
src/main/java/app/services/db/web/CollectStatisticFilter.java

@ -0,0 +1,21 @@
package app.services.db.web;
import app.entities.db.CollectableStatistic;
import java.util.function.Predicate;
enum CollectStatisticFilter {
SERVER_REQUEST((c) -> c.getClient_ip() != null && c.getClient_ip().equals("192.168.3.3") && c.getPath() != null && c.getPath().equals("/api/stats")),
API_IGNORE_RULE((c) -> c.getPath() != null && c.getPath().equals("/api/stats") && c.getQuery() != null && !c.getQuery().contains("filter=servers")),
DISCORD_WEB_BOT((c) -> c.getUseragent().contains("Discordbot/2.0; +https://discordapp.com"));
private final Predicate<CollectableStatistic> rule;
CollectStatisticFilter(Predicate<CollectableStatistic> rule) {
this.rule = rule;
}
public boolean check(CollectableStatistic collectableStatistic) {
return rule.test(collectableStatistic);
}
}

10
src/main/java/app/services/db/CollectStatisticService.java → src/main/java/app/services/db/web/CollectStatisticService.java

@ -1,4 +1,4 @@
package app.services.db;
package app.services.db.web;
import app.entities.db.CollectableStatistic;
import app.updates.BaseUpdater;
@ -20,8 +20,12 @@ public class CollectStatisticService extends BaseUpdater {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public void add(CollectableStatistic collectableStatistic) {
if (collectableStatistic.isServerRequest()) return;
if (collectableStatistic.isIgnoreRule()) return;
for(CollectStatisticFilter f:CollectStatisticFilter.values()) {
if (f.check(collectableStatistic)) {
return;
}
}
try {
if (!collectableStatistic.isStatsRequests())
logger.info(collectableStatistic.toString());
Loading…
Cancel
Save