From 33a6beadd61262376e15c661c65203da91a68690 Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 17 Jan 2026 14:31:54 +0300 Subject: [PATCH] =?UTF-8?q?=D1=85=D1=83=D0=B9=20=D0=B7=D0=BD=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D1=87=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/web/CollectStatisticFilter.java | 3 +- .../db/web/CollectStatisticService.java | 55 ++++++++++++++----- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/main/java/app/services/db/web/CollectStatisticFilter.java b/src/main/java/app/services/db/web/CollectStatisticFilter.java index ec7fc1e..77a679b 100644 --- a/src/main/java/app/services/db/web/CollectStatisticFilter.java +++ b/src/main/java/app/services/db/web/CollectStatisticFilter.java @@ -7,7 +7,8 @@ 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")); + 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 rule; diff --git a/src/main/java/app/services/db/web/CollectStatisticService.java b/src/main/java/app/services/db/web/CollectStatisticService.java index 23dbd7e..a952480 100644 --- a/src/main/java/app/services/db/web/CollectStatisticService.java +++ b/src/main/java/app/services/db/web/CollectStatisticService.java @@ -6,9 +6,16 @@ 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.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; +import java.time.Instant; +import java.util.LinkedList; +import java.util.Queue; +import java.util.UUID; + @Service public class CollectStatisticService extends BaseUpdater { @@ -17,25 +24,43 @@ public class CollectStatisticService extends BaseUpdater { @Qualifier("jt_rw") private JdbcTemplate jdbcTemplate; + private Queue q = new LinkedList<>(); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public void add(CollectableStatistic collectableStatistic) { - for(CollectStatisticFilter f:CollectStatisticFilter.values()) { - if (f.check(collectableStatistic)) { - return; - } - } + @EventListener(ApplicationReadyEvent.class) + public void createCollector() { + CreateTaskUpdater(this::collector, 50, "stats collector"); + } - try { - if (!collectableStatistic.isStatsRequests()) - logger.info(collectableStatistic.toString()); + public Object collector() { + CollectableStatistic collectableStatistic = q.poll(); + 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 (?, ?, ?, ?, ?, ?)", - collectableStatistic.getSteam64(), collectableStatistic.getClient_ip(), - collectableStatistic.getMethod(), collectableStatistic.getPath(), - collectableStatistic.getQuery(), collectableStatistic.getUseragent()); - } catch (Exception err) { - logger.error("Ignoring add stats"); + UUID rnd = UUID.randomUUID(); + Long cur = Instant.now().getEpochSecond(); + logger.info("[~] Stats " + rnd.toString()); + jdbcTemplate.update("INSERT INTO web_statistic (steam64, client_ip, method, path, query, useragent) VALUES (?, ?, ?, ?, ?, ?)", + collectableStatistic.getSteam64(), collectableStatistic.getClient_ip(), + 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); } }