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