Browse Source

collect statistic v1 fix3

master
gsd 1 year ago
parent
commit
376a1ebc48
  1. 8
      src/main/java/app/entities/db/CollectableStatistic.java
  2. 11
      src/main/java/app/services/db/CollectStatisticService.java

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

@ -50,4 +50,12 @@ public class CollectableStatistic {
String[] rawCookieParams = request.getHeader("Cookie").split(";");
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");
}
}

11
src/main/java/app/services/db/CollectStatisticService.java

@ -4,6 +4,8 @@ import app.entities.db.CollectableStatistic;
import app.updates.BaseUpdater;
import jakarta.annotation.PostConstruct;
import jakarta.persistence.EntityManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@ -19,6 +21,8 @@ public class CollectStatisticService extends BaseUpdater {
private EntityManager entityManager;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
public CollectStatisticService(@Qualifier(value = "RwEntityManager") EntityManager entityManager) {
this.entityManager = entityManager;
@ -26,7 +30,9 @@ public class CollectStatisticService extends BaseUpdater {
@Transactional("RwTransactionManager")
public void add(CollectableStatistic collectableStatistic) {
if (collectableStatistic.getClient_ip() != null && collectableStatistic.getClient_ip().equals("192.168.3.3") && collectableStatistic.getPath().equals("/api/stats")) return;
if (collectableStatistic.isServerRequest()) return;
if (collectableStatistic.isIgnoreRule()) return;
try {
entityManager.createNativeQuery("INSERT INTO `web_statistic` (`steam64`, `client_ip`, `method`, `path`, `query`, `useragent`) VALUES (?1, ?2, ?3, ?4, ?5, ?6)")
.setParameter(1, collectableStatistic.getSteam64())
.setParameter(2, collectableStatistic.getClient_ip())
@ -35,5 +41,8 @@ public class CollectStatisticService extends BaseUpdater {
.setParameter(5, collectableStatistic.getQuery())
.setParameter(6, collectableStatistic.getUseragent())
.executeUpdate();
} catch (Exception err) {
logger.error("Ignoring add stats");
}
}
}

Loading…
Cancel
Save