Search in sources :

Example 1 with TPSStoreTransaction

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()));
}
Also used : TPSStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction)

Example 2 with TPSStoreTransaction

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()));
}
Also used : TPSStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction)

Example 3 with TPSStoreTransaction

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());
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 4 with TPSStoreTransaction

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());
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 5 with TPSStoreTransaction

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());
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

TPSStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction)5 TPS (com.djrapitops.plan.gathering.domain.TPS)3 Test (org.junit.jupiter.api.Test)3