Browse Source

хуй знает что

master
gsd 5 months ago
parent
commit
33a6beadd6
  1. 3
      src/main/java/app/services/db/web/CollectStatisticFilter.java
  2. 55
      src/main/java/app/services/db/web/CollectStatisticService.java

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

@ -7,7 +7,8 @@ import java.util.function.Predicate;
enum CollectStatisticFilter { 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")), 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")), 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")); DISCORD_WEB_BOT((c) -> c.getUseragent().contains("Discordbot/2.0; +https://discordapp.com")),
DUMMY_PROFILE((c) -> "/api/profile/current".equals(c.getPath()) && "requests=pohuy&steam64=null".equals(c.getQuery()));
private final Predicate<CollectableStatistic> rule; private final Predicate<CollectableStatistic> rule;

55
src/main/java/app/services/db/web/CollectStatisticService.java

@ -6,9 +6,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.LinkedList;
import java.util.Queue;
import java.util.UUID;
@Service @Service
public class CollectStatisticService extends BaseUpdater { public class CollectStatisticService extends BaseUpdater {
@ -17,25 +24,43 @@ public class CollectStatisticService extends BaseUpdater {
@Qualifier("jt_rw") @Qualifier("jt_rw")
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
private Queue<CollectableStatistic> q = new LinkedList<>();
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());
public void add(CollectableStatistic collectableStatistic) { @EventListener(ApplicationReadyEvent.class)
for(CollectStatisticFilter f:CollectStatisticFilter.values()) { public void createCollector() {
if (f.check(collectableStatistic)) { CreateTaskUpdater(this::collector, 50, "stats collector");
return; }
}
}
try { public Object collector() {
if (!collectableStatistic.isStatsRequests()) CollectableStatistic collectableStatistic = q.poll();
logger.info(collectableStatistic.toString()); if (collectableStatistic != null) {
for(CollectStatisticFilter f:CollectStatisticFilter.values()) {
if (f.check(collectableStatistic)) {
return null;
}
}
try {
if (!collectableStatistic.isStatsRequests())
logger.info(collectableStatistic.toString());
jdbcTemplate.update("INSERT INTO web_statistic (steam64, client_ip, method, path, query, useragent) VALUES (?, ?, ?, ?, ?, ?)", UUID rnd = UUID.randomUUID();
collectableStatistic.getSteam64(), collectableStatistic.getClient_ip(), Long cur = Instant.now().getEpochSecond();
collectableStatistic.getMethod(), collectableStatistic.getPath(), logger.info("[~] Stats " + rnd.toString());
collectableStatistic.getQuery(), collectableStatistic.getUseragent()); jdbcTemplate.update("INSERT INTO web_statistic (steam64, client_ip, method, path, query, useragent) VALUES (?, ?, ?, ?, ?, ?)",
} catch (Exception err) { collectableStatistic.getSteam64(), collectableStatistic.getClient_ip(),
logger.error("Ignoring add stats"); collectableStatistic.getMethod(), collectableStatistic.getPath(),
collectableStatistic.getQuery(), collectableStatistic.getUseragent());
logger.info("[+] Stats " + rnd.toString() + " ts: " + (Instant.now().getEpochSecond() - cur) + "s");
} catch (Exception err) {
logger.error("Ignoring add stats");
}
} }
return null;
}
public void add(CollectableStatistic collectableStatistic) {
q.offer(collectableStatistic);
} }
} }

Loading…
Cancel
Save