diff --git a/core/pom.xml b/core/pom.xml index a184bd28..a0d8d27a 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -6,11 +6,11 @@ io.memoria atom - 22.3.0 + 22.4.0 io.memoria.atom core - 22.3.0 + 22.4.0 jar ${project.groupId}.${project.artifactId} Core Module diff --git a/eventsourcing/pom.xml b/eventsourcing/pom.xml index c84ae733..30316dd5 100644 --- a/eventsourcing/pom.xml +++ b/eventsourcing/pom.xml @@ -6,12 +6,12 @@ io.memoria atom - 22.3.0 + 22.4.0 io.memoria.atom eventsourcing - 22.3.0 + 22.4.0 jar ${project.groupId}.${project.artifactId} diff --git a/pom.xml b/pom.xml index 439efead..59eb2f37 100755 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ io.memoria atom - 22.3.0 + 22.4.0 pom ${project.groupId}.${project.artifactId} diff --git a/web/pom.xml b/web/pom.xml index 4f9f9aee..242d658f 100755 --- a/web/pom.xml +++ b/web/pom.xml @@ -6,11 +6,11 @@ io.memoria atom - 22.3.0 + 22.4.0 io.memoria.atom web - 22.3.0 + 22.4.0 jar ${project.groupId}.${project.artifactId} Web module diff --git a/web/src/main/java/io/memoria/atom/web/observability/PrometheusRegistryBuilder.java b/web/src/main/java/io/memoria/atom/web/observability/PrometheusRegistryBuilder.java index fafd6203..fb59d0f3 100644 --- a/web/src/main/java/io/memoria/atom/web/observability/PrometheusRegistryBuilder.java +++ b/web/src/main/java/io/memoria/atom/web/observability/PrometheusRegistryBuilder.java @@ -1,7 +1,7 @@ package io.memoria.atom.web.observability; -import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; @@ -18,21 +18,39 @@ import java.util.List; public class PrometheusRegistryBuilder { - private final PrometheusMeterRegistry registry; + public static final String APPLICATION_NAME_TAG = "APPLICATION_NAME"; + public static final String APPLICATION_VERSION_TAG = "APPLICATION_VERSION"; + private final List tagList; + private final List meters; + private final PrometheusMeterRegistry registry; - public PrometheusRegistryBuilder(String appName, String version) { + public PrometheusRegistryBuilder() { + this(PrometheusConfig.DEFAULT); + } + + public PrometheusRegistryBuilder(PrometheusConfig prometheusConfig) { this.tagList = new ArrayList<>(); - this.tagList.add(Tag.of("APPLICATION_NAME", appName)); - this.tagList.add(Tag.of("APPLICATION_VERSION", version)); - registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); + this.meters = new ArrayList<>(); + this.registry = new PrometheusMeterRegistry(prometheusConfig); } public PrometheusMeterRegistry build() { registry.config().commonTags(tagList); + this.meters.forEach(m -> m.bindTo(registry)); return registry; } + public PrometheusRegistryBuilder withAppNameTag(String applicationName) { + this.tagList.add(Tag.of(APPLICATION_NAME_TAG, applicationName)); + return this; + } + + public PrometheusRegistryBuilder withAppVersionTag(String applicationVersion) { + this.tagList.add(Tag.of(APPLICATION_VERSION_TAG, applicationVersion)); + return this; + } + public PrometheusRegistryBuilder withTag(Tag tag) { this.tagList.add(tag); return this; @@ -43,54 +61,53 @@ public PrometheusRegistryBuilder withTags(List tags) { return this; } - public PrometheusRegistryBuilder withDefaultMetrics(PrometheusMeterRegistry registry) { - return withLog4j2Metrics(registry).withThreadMetrics(registry) - .withGCMetrics(registry) - .withMemoryMetrics(registry) - .withDiskSpaceMetrics(registry) - .withProcessorMetrics(registry) - .withUptimeMetrics(registry); + public PrometheusRegistryBuilder withDefaultMetrics() { + return withLog4j2Metrics().withThreadMetrics() + .withGCMetrics() + .withMemoryMetrics() + .withDiskSpaceMetrics() + .withProcessorMetrics() + .withUptimeMetrics(); } - @SuppressWarnings("resource") - public PrometheusRegistryBuilder withLog4j2Metrics(MeterRegistry registry) { - new Log4j2Metrics().bindTo(registry); + public PrometheusRegistryBuilder withLog4j2Metrics() { + this.meters.add(new Log4j2Metrics()); return this; } - public PrometheusRegistryBuilder withThreadMetrics(MeterRegistry registry) { - new ClassLoaderMetrics().bindTo(registry); - new JvmThreadMetrics().bindTo(registry); + public PrometheusRegistryBuilder withThreadMetrics() { + this.meters.add(new ClassLoaderMetrics()); + this.meters.add(new JvmThreadMetrics()); return this; } - @SuppressWarnings({"java:S2095", "resource"}) + @SuppressWarnings({"java:S2095"}) // Do not change JvmGcMetrics to try-with-resources as the JvmGcMetrics will not be available after (auto-)closing. // See https://github.com/micrometer-metrics/micrometer/issues/1492 - public PrometheusRegistryBuilder withGCMetrics(MeterRegistry registry) { + public PrometheusRegistryBuilder withGCMetrics() { JvmGcMetrics jvmGcMetrics = new JvmGcMetrics(); - jvmGcMetrics.bindTo(registry); + this.meters.add(jvmGcMetrics); Runtime.getRuntime().addShutdownHook(new Thread(jvmGcMetrics::close)); return this; } - public PrometheusRegistryBuilder withMemoryMetrics(MeterRegistry registry) { - new JvmMemoryMetrics().bindTo(registry); + public PrometheusRegistryBuilder withMemoryMetrics() { + this.meters.add(new JvmMemoryMetrics()); return this; } - public PrometheusRegistryBuilder withDiskSpaceMetrics(MeterRegistry registry) { - new DiskSpaceMetrics(new File("/")).bindTo(registry); + public PrometheusRegistryBuilder withDiskSpaceMetrics() { + this.meters.add(new DiskSpaceMetrics(new File("/"))); return this; } - public PrometheusRegistryBuilder withProcessorMetrics(MeterRegistry registry) { - new ProcessorMetrics().bindTo(registry); + public PrometheusRegistryBuilder withProcessorMetrics() { + this.meters.add(new ProcessorMetrics()); return this; } - public PrometheusRegistryBuilder withUptimeMetrics(MeterRegistry registry) { - new UptimeMetrics().bindTo(registry); + public PrometheusRegistryBuilder withUptimeMetrics() { + this.meters.add(new UptimeMetrics()); return this; } } \ No newline at end of file diff --git a/xcassandra/pom.xml b/xcassandra/pom.xml index dce9d9e4..f3770274 100755 --- a/xcassandra/pom.xml +++ b/xcassandra/pom.xml @@ -6,12 +6,12 @@ io.memoria atom - 22.3.0 + 22.4.0 io.memoria.atom xcassandra - 22.3.0 + 22.4.0 jar ${project.groupId}.${project.artifactId} diff --git a/xjackson/pom.xml b/xjackson/pom.xml index 66ba7b30..c1f9cdf6 100755 --- a/xjackson/pom.xml +++ b/xjackson/pom.xml @@ -6,11 +6,11 @@ io.memoria atom - 22.3.0 + 22.4.0 io.memoria.atom xjackson - 22.3.0 + 22.4.0 jar ${project.groupId}.${project.artifactId} text Module