diff --git a/src/fr/devinsy/statoolinfos/metrics/gitea/GiteaProber.java b/src/fr/devinsy/statoolinfos/metrics/gitea/GiteaProber.java index fbfae97..f1bb2dc 100644 --- a/src/fr/devinsy/statoolinfos/metrics/gitea/GiteaProber.java +++ b/src/fr/devinsy/statoolinfos/metrics/gitea/GiteaProber.java @@ -88,6 +88,7 @@ public class GiteaProber SQLDatabase database = new SQLDatabase(databaseConfig.getUrl(), databaseConfig.getUser(), databaseConfig.getPassword()); database.open(); result.putAll(DatabaseProber.probe(database)); + database.close(); } else { diff --git a/src/fr/devinsy/statoolinfos/metrics/minetest/MinetestProber.java b/src/fr/devinsy/statoolinfos/metrics/minetest/MinetestProber.java index 70e67f8..fae15a4 100644 --- a/src/fr/devinsy/statoolinfos/metrics/minetest/MinetestProber.java +++ b/src/fr/devinsy/statoolinfos/metrics/minetest/MinetestProber.java @@ -73,55 +73,63 @@ public class MinetestProber result = MinetestLogAnalyzer.probe(logs); // metrics.service.database.bytes - long databaseSize = 0; - try - { - System.out.println("Probing database [" + playerDatabaseConfig.getUrl() + "]"); - if (playerDatabaseConfig.isSet()) - { - SQLDatabase database = new SQLDatabase(playerDatabaseConfig.getUrl(), playerDatabaseConfig.getUser(), playerDatabaseConfig.getPassword()); - database.open(); - databaseSize += database.getDatabaseSize(); - } - else - { - System.out.println("Minetest Players Database undefined."); - } - } - catch (SQLException exception) - { - logger.error("ERROR with database.", exception); - } - - if (!StringUtils.equals(playerDatabaseConfig.getUrl(), worldDatabaseConfig.getUrl())) + // metrics.service.accounts { + long databaseSize = 0; + StringList timemarks = result.getNowTimeMarks(); try { - System.out.println("Probing database [" + worldDatabaseConfig.getUrl() + "]"); - if (worldDatabaseConfig.isSet()) + System.out.println("Probing database [" + playerDatabaseConfig.getUrl() + "]"); + if (playerDatabaseConfig.isSet()) { - SQLDatabase database = new SQLDatabase(worldDatabaseConfig.getUrl(), worldDatabaseConfig.getUser(), worldDatabaseConfig.getPassword()); + SQLDatabase database = new SQLDatabase(playerDatabaseConfig.getUrl(), playerDatabaseConfig.getUser(), playerDatabaseConfig.getPassword()); database.open(); databaseSize += database.getDatabaseSize(); + + // metrics.service.accounts + long accountCount = database.queryNumber("select count(*) from player;"); + result.set(accountCount, "metrics.service.accounts", timemarks); + + // + database.close(); } else { - System.out.println("Minetest Worlds Database undefined."); + System.out.println("Minetest Players Database undefined."); } } catch (SQLException exception) { logger.error("ERROR with database.", exception); } + + if (!StringUtils.equals(playerDatabaseConfig.getUrl(), worldDatabaseConfig.getUrl())) + { + try + { + System.out.println("Probing database [" + worldDatabaseConfig.getUrl() + "]"); + if (worldDatabaseConfig.isSet()) + { + SQLDatabase database = new SQLDatabase(worldDatabaseConfig.getUrl(), worldDatabaseConfig.getUser(), worldDatabaseConfig.getPassword()); + database.open(); + databaseSize += database.getDatabaseSize(); + database.close(); + } + else + { + System.out.println("Minetest Worlds Database undefined."); + } + } + catch (SQLException exception) + { + logger.error("ERROR with database.", exception); + } + } + + // metrics.service.database.bytes + result.set(databaseSize, "metrics.service.database.bytes", timemarks); } - StringList timemarks = result.getNowTimeMarks(); - result.set(databaseSize, "metrics.service.database.bytes", timemarks); - - // result.putAll(MumbleDatabaseAnalyzer.probe()); - // metrics.service.accounts - // metrics.service.database.bytes - // metrics.service.files.bytes // diff --git a/src/fr/devinsy/statoolinfos/util/sql/SQLDatabase.java b/src/fr/devinsy/statoolinfos/util/sql/SQLDatabase.java index 1787b24..ed6fc49 100644 --- a/src/fr/devinsy/statoolinfos/util/sql/SQLDatabase.java +++ b/src/fr/devinsy/statoolinfos/util/sql/SQLDatabase.java @@ -355,7 +355,7 @@ public class SQLDatabase this.connection = DriverManager.getConnection(this.url, this.login, this.password); this.status = Status.OPENED; - logger.info("Single connection opened with [{}].", this.url); + logger.info("Single connection opened with [{}].", this.url); } } catch (ClassNotFoundException exception)