Search in sources :

Example 71 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class NetworkPerformanceJSONResolver method createJSONAsMap.

public Map<String, Object> createJSONAsMap(Collection<ServerUUID> serverUUIDs) {
    Map<String, Object> serverOverview = new HashMap<>();
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Map<Integer, List<TPS>> tpsData = db.query(TPSQueries.fetchTPSDataOfServers(monthAgo, now, serverUUIDs));
    serverOverview.put("numbers", createNumbersMap(tpsData));
    return serverOverview;
}
Also used : Database(com.djrapitops.plan.storage.database.Database)

Example 72 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class ServerPlaceHolders method register.

@Override
public void register(PlanPlaceholders placeholders) {
    Formatter<Double> decimals = formatters.decimals();
    Formatter<Double> percentage = formatters.percentage();
    Database database = dbSystem.getDatabase();
    placeholders.registerStatic("server_players_registered_total", parameters -> database.query(PlayerCountQueries.newPlayerCount(0, now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_players_registered_day", parameters -> database.query(PlayerCountQueries.newPlayerCount(dayAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_players_registered_week", parameters -> database.query(PlayerCountQueries.newPlayerCount(weekAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_players_registered_month", parameters -> database.query(PlayerCountQueries.newPlayerCount(monthAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("network_players_registered_total", parameters -> database.query(PlayerCountQueries.newPlayerCount(0, now())));
    placeholders.registerStatic("network_players_registered_day", parameters -> database.query(PlayerCountQueries.newPlayerCount(dayAgo(), now())));
    placeholders.registerStatic("network_players_registered_week", parameters -> database.query(PlayerCountQueries.newPlayerCount(weekAgo(), now())));
    placeholders.registerStatic("network_players_registered_month", parameters -> database.query(PlayerCountQueries.newPlayerCount(monthAgo(), now())));
    placeholders.registerStatic("server_players_unique_total", parameters -> database.query(PlayerCountQueries.newPlayerCount(0, now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_players_unique_day", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(dayAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_players_unique_week", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(weekAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_players_unique_month", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(monthAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("network_players_unique_total", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(0, now())));
    placeholders.registerStatic("network_players_unique_day", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(dayAgo(), now())));
    placeholders.registerStatic("network_players_unique_week", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(weekAgo(), now())));
    placeholders.registerStatic("network_players_unique_month", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(monthAgo(), now())));
    placeholders.registerStatic("server_tps_day", parameters -> decimals.apply(database.query(TPSQueries.averageTPS(dayAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_tps_week", parameters -> decimals.apply(database.query(TPSQueries.averageTPS(weekAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_tps_month", parameters -> decimals.apply(database.query(TPSQueries.averageTPS(monthAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_cpu_day", parameters -> percentage.apply(database.query(TPSQueries.averageCPU(dayAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_cpu_week", parameters -> percentage.apply(database.query(TPSQueries.averageCPU(weekAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_cpu_month", parameters -> percentage.apply(database.query(TPSQueries.averageCPU(monthAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_ram_day", parameters -> formatters.byteSizeLong().apply(database.query(TPSQueries.averageRAM(dayAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_ram_week", parameters -> formatters.byteSizeLong().apply(database.query(TPSQueries.averageRAM(weekAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_ram_month", parameters -> formatters.byteSizeLong().apply(database.query(TPSQueries.averageRAM(monthAgo(), now(), getServerUUID(parameters)))));
    placeholders.registerStatic("server_chunks_day", parameters -> database.query(TPSQueries.averageChunks(dayAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_chunks_week", parameters -> database.query(TPSQueries.averageChunks(weekAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_chunks_month", parameters -> database.query(TPSQueries.averageChunks(monthAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_entities_day", parameters -> database.query(TPSQueries.averageEntities(dayAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_entities_week", parameters -> database.query(TPSQueries.averageEntities(weekAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_entities_month", parameters -> database.query(TPSQueries.averageEntities(monthAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_max_free_disk_day", parameters -> database.query(TPSQueries.maxFreeDisk(dayAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_max_free_disk_week", parameters -> database.query(TPSQueries.maxFreeDisk(weekAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_max_free_disk_month", parameters -> database.query(TPSQueries.maxFreeDisk(monthAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_min_free_disk_day", parameters -> database.query(TPSQueries.minFreeDisk(dayAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_min_free_disk_week", parameters -> database.query(TPSQueries.minFreeDisk(weekAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_min_free_disk_month", parameters -> database.query(TPSQueries.minFreeDisk(monthAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_average_free_disk_day", parameters -> database.query(TPSQueries.averageFreeDisk(dayAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_average_free_disk_week", parameters -> database.query(TPSQueries.averageFreeDisk(weekAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_average_free_disk_month", parameters -> database.query(TPSQueries.averageFreeDisk(monthAgo(), now(), getServerUUID(parameters))));
    placeholders.registerStatic("server_name", () -> serverInfo.getServer().getName());
    placeholders.registerStatic("server_uuid", serverInfo::getServerUUID);
    registerDynamicCategoryPlaceholders(placeholders, database);
}
Also used : Database(com.djrapitops.plan.storage.database.Database)

Example 73 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class NetworkSettingManager method updateConfigFromDBIfUpdated.

private void updateConfigFromDBIfUpdated() {
    Database database = dbSystem.getDatabase();
    Set<ServerUUID> serverUUIDs = database.query(ServerQueries.fetchPlanServerInformation()).keySet();
    // Remove the proxy server from the list
    serverUUIDs.remove(serverInfo.getServerUUID());
    for (ServerUUID serverUUID : serverUUIDs) {
        updateConfigFromDBIfUpdated(database, serverUUID);
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Database(com.djrapitops.plan.storage.database.Database)

Example 74 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class NetworkSettingManager method updateConfigInDB.

public void updateConfigInDB(File file, ServerUUID serverUUID) {
    if (!file.exists()) {
        return;
    }
    Database database = dbSystem.getDatabase();
    try (ConfigReader reader = new ConfigReader(file.toPath())) {
        Config config = reader.read();
        database.executeTransaction(new StoreConfigTransaction(serverUUID, config, file.lastModified()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Database(com.djrapitops.plan.storage.database.Database) UncheckedIOException(java.io.UncheckedIOException) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 75 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class JSErrorRegressionTest method savePlayerData.

private static void savePlayerData() {
    DBSystem dbSystem = planSystem.getDatabaseSystem();
    Database database = dbSystem.getDatabase();
    UUID uuid = TestConstants.PLAYER_ONE_UUID;
    database.executeTransaction(new PlayerRegisterTransaction(uuid, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME));
    FinishedSession session = new FinishedSession(uuid, serverUUID, 1000L, 11000L, 500L, new DataMap());
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, "world"));
    database.executeTransaction(new SessionEndTransaction(session));
}
Also used : SessionEndTransaction(com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction) DBSystem(com.djrapitops.plan.storage.database.DBSystem) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Database(com.djrapitops.plan.storage.database.Database) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) DataMap(com.djrapitops.plan.gathering.domain.DataMap)

Aggregations

Database (com.djrapitops.plan.storage.database.Database)90 ServerUUID (com.djrapitops.plan.identification.ServerUUID)18 HashMap (java.util.HashMap)18 StoreIconTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction)12 ProviderInformation (com.djrapitops.plan.extension.implementation.ProviderInformation)11 UUID (java.util.UUID)10 StoreProviderTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction)9 DBSystem (com.djrapitops.plan.storage.database.DBSystem)9 TPSMutator (com.djrapitops.plan.delivery.domain.mutators.TPSMutator)7 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)7 PlayerName (com.djrapitops.plan.delivery.domain.PlayerName)6 ServerName (com.djrapitops.plan.delivery.domain.ServerName)6 Point (com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)6 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)6 ServerInfo (com.djrapitops.plan.identification.ServerInfo)6 InetAddress (java.net.InetAddress)6 Inject (javax.inject.Inject)6 DateObj (com.djrapitops.plan.delivery.domain.DateObj)5 LineGraphFactory (com.djrapitops.plan.delivery.rendering.json.graphs.line.LineGraphFactory)5 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)5