diff --git a/database-manipulation-tool/src/main/java/io/skodjob/dmt/model/Database.java b/database-manipulation-tool/src/main/java/io/skodjob/dmt/database/Database.java similarity index 84% rename from database-manipulation-tool/src/main/java/io/skodjob/dmt/model/Database.java rename to database-manipulation-tool/src/main/java/io/skodjob/dmt/database/Database.java index cb6013a..b8333f4 100644 --- a/database-manipulation-tool/src/main/java/io/skodjob/dmt/model/Database.java +++ b/database-manipulation-tool/src/main/java/io/skodjob/dmt/database/Database.java @@ -3,13 +3,20 @@ * * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package io.skodjob.dmt.model; +package io.skodjob.dmt.database; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; +import io.micrometer.prometheus.PrometheusMeterRegistry; +import io.skodjob.dmt.model.DatabaseColumn; +import io.skodjob.dmt.model.DatabaseEntry; +import io.skodjob.dmt.model.DatabaseTable; +import io.skodjob.dmt.model.DatabaseTableMetadata; import jakarta.enterprise.context.ApplicationScoped; import io.skodjob.dmt.exception.InnerDatabaseException; @@ -20,12 +27,15 @@ @Lock @ApplicationScoped public class Database { + private final MeterRegistry meterRegistry; Map tables; private static final Logger LOG = Logger.getLogger(Database.class); - public Database() { + public Database(PrometheusMeterRegistry meterRegistry) { tables = new HashMap<>(); + this.meterRegistry = meterRegistry; + meterRegistry.gaugeMapSize("table.count", Tags.empty(), tables); } @Lock(value = Lock.Type.READ) @@ -119,5 +129,6 @@ public List getTables() { private void createTable(DatabaseTableMetadata tableMetadata) { tables.put(tableMetadata.getName(), new DatabaseTable(tableMetadata)); + meterRegistry.gaugeMapSize(tableMetadata.getName() + ".table.size", Tags.empty(), tables.get(tableMetadata.getName()).getRowsAsMap()); } } diff --git a/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/MainService.java b/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/MainService.java index 7bfd763..f376ad3 100644 --- a/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/MainService.java +++ b/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/MainService.java @@ -19,7 +19,7 @@ import io.skodjob.dmt.dao.Dao; import io.skodjob.dmt.dao.DaoManager; import io.skodjob.dmt.exception.InnerDatabaseException; -import io.skodjob.dmt.model.Database; +import io.skodjob.dmt.database.Database; import io.skodjob.dmt.model.DatabaseColumn; import io.skodjob.dmt.model.DatabaseEntry; import io.skodjob.dmt.model.DatabaseTableMetadata; diff --git a/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/UtilityService.java b/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/UtilityService.java index 080d20d..a640b4b 100644 --- a/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/UtilityService.java +++ b/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/UtilityService.java @@ -12,7 +12,7 @@ import org.jboss.logging.Logger; import io.skodjob.dmt.dao.DaoManager; -import io.skodjob.dmt.model.Database; +import io.skodjob.dmt.database.Database; import io.skodjob.dmt.utils.ResponseJsonBuilder; @ApplicationScoped diff --git a/database-manipulation-tool/src/main/java/io/skodjob/dmt/utils/ResponseJsonBuilder.java b/database-manipulation-tool/src/main/java/io/skodjob/dmt/utils/ResponseJsonBuilder.java index 59bbab2..09460f2 100644 --- a/database-manipulation-tool/src/main/java/io/skodjob/dmt/utils/ResponseJsonBuilder.java +++ b/database-manipulation-tool/src/main/java/io/skodjob/dmt/utils/ResponseJsonBuilder.java @@ -12,7 +12,7 @@ import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; -import io.skodjob.dmt.model.Database; +import io.skodjob.dmt.database.Database; import io.skodjob.dmt.model.DatabaseColumnEntry; import io.skodjob.dmt.model.DatabaseTable; import io.skodjob.dmt.model.DatabaseColumn;