Skip to content

Commit

Permalink
Add prometheus metrics to inner database
Browse files Browse the repository at this point in the history
  • Loading branch information
novotnyJiri committed Mar 25, 2024
1 parent 4b0e836 commit 0612bbf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,12 +27,15 @@
@Lock
@ApplicationScoped
public class Database {
private final MeterRegistry meterRegistry;
Map<String, DatabaseTable> 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)
Expand Down Expand Up @@ -119,5 +129,6 @@ public List<DatabaseTable> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0612bbf

Please sign in to comment.