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 {
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<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.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<CollectableStatistic> 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);
}
}

Loading…
Cancel
Save