|
|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|