use of com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction in project Plan by plan-player-analytics.
the class ProxyTPSCounter method save.
private void save(long time) {
long timeLastMinute = time - TimeUnit.MINUTES.toMillis(1L);
int maxPlayers = playersOnline.getMaxAndReset();
double averageCPU = cpu.getAverageAndReset();
long averageRAM = (long) ram.getAverageAndReset(time);
long freeDiskSpace = systemUsage.getFreeDiskSpace();
dbSystem.getDatabase().executeTransaction(new TPSStoreTransaction(serverInfo.getServerUUID(), TPSBuilder.get().date(timeLastMinute).playersOnline(maxPlayers).usedCPU(averageCPU).usedMemory(averageRAM).freeDiskSpace(freeDiskSpace).toTPS()));
}
use of com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction in project Plan by plan-player-analytics.
the class ServerTPSCounter method save.
private void save(double averageTPS, long time) {
long timeLastMinute = time - TimeUnit.MINUTES.toMillis(1L);
int maxPlayers = playersOnline.getMaxAndReset();
double averageCPU = cpu.getAverageAndReset();
long averageRAM = (long) ram.getAverageAndReset();
int entityCount = 0;
int chunkCount = 0;
for (W world : serverSensor.getWorlds()) {
entityCount += serverSensor.getEntityCount(world);
chunkCount += serverSensor.getChunkCount(world);
}
long freeDiskSpace = systemUsage.getFreeDiskSpace();
dbSystem.getDatabase().executeTransaction(new TPSStoreTransaction(serverInfo.getServerUUID(), TPSBuilder.get().date(timeLastMinute).tps(averageTPS).playersOnline(maxPlayers).usedCPU(averageCPU).usedMemory(averageRAM).entities(entityCount).chunksLoaded(chunkCount).freeDiskSpace(freeDiskSpace).toTPS()));
}
use of com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction in project Plan by plan-player-analytics.
the class TPSQueriesTest method serverStartDateIsFetched.
@Test
default void serverStartDateIsFetched() {
List<TPS> tpsData = RandomData.randomTPS();
TPS stored = tpsData.get(0);
TPS stored2 = TPSBuilder.get().date(stored.getDate() + TimeUnit.MINUTES.toMillis(1L)).toTPS();
db().executeTransaction(new TPSStoreTransaction(serverUUID(), stored));
db().executeTransaction(new TPSStoreTransaction(serverUUID(), stored2));
Optional<Long> result = db().query(TPSQueries.fetchLatestServerStartTime(serverUUID(), TimeUnit.MINUTES.toMillis(3)));
assertTrue(result.isPresent());
assertEquals(stored.getDate(), result.get());
}
use of com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction in project Plan by plan-player-analytics.
the class TPSQueriesTest method playerMaxPeakIsCorrect.
@Test
default void playerMaxPeakIsCorrect() {
List<TPS> tpsData = RandomData.randomTPS();
for (TPS tps : tpsData) {
db().executeTransaction(new TPSStoreTransaction(serverUUID(), tps));
}
tpsData.sort(Comparator.comparingInt(TPS::getPlayers));
int expected = tpsData.get(tpsData.size() - 1).getPlayers();
int actual = db().query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID())).map(DateObj::getValue).orElse(-1);
assertEquals(expected, actual, () -> "Wrong return value. " + Lists.map(tpsData, TPS::getPlayers).toString());
}
use of com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction in project Plan by plan-player-analytics.
the class TPSQueriesTest method serverStartDateIsCorrect.
@Test
default void serverStartDateIsCorrect() {
List<TPS> tpsData = RandomData.randomTPS();
TPS stored = tpsData.get(0);
TPS stored2 = TPSBuilder.get().date(stored.getDate() + TimeUnit.MINUTES.toMillis(4L)).toTPS();
TPS stored3 = TPSBuilder.get().date(stored.getDate() + TimeUnit.MINUTES.toMillis(5L)).toTPS();
db().executeTransaction(new TPSStoreTransaction(serverUUID(), stored));
db().executeTransaction(new TPSStoreTransaction(serverUUID(), stored2));
db().executeTransaction(new TPSStoreTransaction(serverUUID(), stored3));
Optional<Long> result = db().query(TPSQueries.fetchLatestServerStartTime(serverUUID(), TimeUnit.MINUTES.toMillis(3)));
assertTrue(result.isPresent());
assertEquals(stored2.getDate(), result.get());
}
Aggregations