Skip to content

Commit

Permalink
Moved QuaDer metrics exporter to Singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
JPugetGil committed Nov 7, 2024
1 parent 6b0a9ee commit 41592ec
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 45 deletions.
74 changes: 74 additions & 0 deletions quads-loader/src/main/java/fr/vcity/converg/MetricsSingleton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package fr.vcity.converg;

import io.prometheus.metrics.core.metrics.Counter;
import io.prometheus.metrics.core.metrics.Summary;
import io.prometheus.metrics.model.snapshots.Unit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

public class MetricsSingleton {

private static final Logger log = LoggerFactory.getLogger(MetricsSingleton.class);

private static MetricsSingleton metricsSingleton;

public Counter counterVersionTotal;

public Summary summaryVersionBatchingDuration;

public Summary summaryVersionCatalogDuration;

public Summary summaryVersionCondensingDuration;

/**
* Constructor method in order to create db connection & statement
*/
private MetricsSingleton() {
counterVersionTotal =
Counter.builder()
.name("version_count_total")
.help("number of version that have been imported in the database")
.register();

summaryVersionBatchingDuration =
Summary.builder()
.name("file_at_version_batching_duration_seconds")
.help("duration of the file batching in seconds at a certain version")
.unit(Unit.SECONDS)
.labelNames("filename", "version")
.register();

summaryVersionCatalogDuration =
Summary.builder()
.name("file_at_version_catalog_duration_seconds")
.help("duration of the file catalog in seconds at a certain version")
.unit(Unit.SECONDS)
.labelNames("filename", "version")
.register();

summaryVersionCondensingDuration =
Summary.builder()
.name("file_at_version_condensing_duration_seconds")
.help("duration of the file condensing in seconds at a certain version")
.unit(Unit.SECONDS)
.labelNames("filename", "version")
.register();
}

/**
* Create the instance of {@link MetricsSingleton} object if it is not created yet and guarantee that there is only one single instance is created for this class.
*
* @return MetricsSingleton created single instance
*/
public static MetricsSingleton getInstance() {
log.info("MetricsSingleton.getInstance()");

if (Objects.isNull(metricsSingleton)) {
metricsSingleton = new MetricsSingleton();
}

return metricsSingleton;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package fr.vcity.converg;

import io.prometheus.metrics.core.metrics.Counter;
import io.prometheus.metrics.instrumentation.jvm.JvmMetrics;
import io.prometheus.metrics.exporter.httpserver.HTTPServer;
import io.prometheus.metrics.model.snapshots.Unit;
import io.prometheus.metrics.instrumentation.jvm.JvmMetrics;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand All @@ -12,7 +10,7 @@
@SpringBootApplication
public class QuadsLoaderApplication {

public static void main(String[] args) throws IOException, InterruptedException {
public static void main(String[] args) throws IOException {
SpringApplication.run(QuadsLoaderApplication.class, args);

JvmMetrics.builder().register();
Expand All @@ -21,19 +19,7 @@ public static void main(String[] args) throws IOException, InterruptedException
.port(9400)
.buildAndStart();

Counter counter =
Counter.builder()
.name("uptime_seconds_total")
.help("total number of seconds since this application was started")
.unit(Unit.SECONDS)
.register();

System.out.println(
"HTTPServer listening on port:" + server.getPort() + "/metrics");

while (true) {
Thread.sleep(1000);
counter.inc();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.vcity.converg.services;

import fr.vcity.converg.MetricsSingleton;
import fr.vcity.converg.dao.ResourceOrLiteral;
import fr.vcity.converg.dao.Version;
import fr.vcity.converg.repository.*;
Expand Down Expand Up @@ -73,35 +74,13 @@ public record QuadValueType(TripleValueType tripleValueType, String namedGraph,
Set<String> namedGraphs = new HashSet<>();
List<TripleValueType> tripleValueTypes = new ArrayList<>();

Counter counterVersionTotal =
Counter.builder()
.name("version_count_total")
.help("number of version that have been imported in the database")
.register();

Summary summaryVersionBatchingDuration =
Summary.builder()
.name("file_at_version_batching_duration_seconds")
.help("duration of the file batching in seconds at a certain version")
.unit(Unit.SECONDS)
.labelNames("filename", "version")
.register();

Summary summaryVersionCatalogDuration =
Summary.builder()
.name("file_at_version_catalog_duration_seconds")
.help("duration of the file catalog in seconds at a certain version")
.unit(Unit.SECONDS)
.labelNames("filename", "version")
.register();

Summary summaryVersionCondensingDuration =
Summary.builder()
.name("file_at_version_condensing_duration_seconds")
.help("duration of the file condensing in seconds at a certain version")
.unit(Unit.SECONDS)
.labelNames("filename", "version")
.register();
Counter counterVersionTotal = MetricsSingleton.getInstance().counterVersionTotal;

Summary summaryVersionBatchingDuration = MetricsSingleton.getInstance().summaryVersionBatchingDuration;

Summary summaryVersionCatalogDuration = MetricsSingleton.getInstance().summaryVersionCatalogDuration;

Summary summaryVersionCondensingDuration = MetricsSingleton.getInstance().summaryVersionCondensingDuration;

public QuadImportService(
IFlatModelQuadRepository flatModelQuadRepository,
Expand Down

0 comments on commit 41592ec

Please sign in to comment.