From 6b07cde2a3592ccaeba36bcc345aeccf6f506395 Mon Sep 17 00:00:00 2001 From: Sergii Chernysh Date: Wed, 25 Nov 2020 12:24:13 +0200 Subject: [PATCH 1/2] Plug in JVM metrics submission via metrics engine --- pom.xml | 5 +++++ .../server/spring/config/MetricsConfiguration.java | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 74bf827503a..3b1dfc16daa 100644 --- a/pom.xml +++ b/pom.xml @@ -235,6 +235,11 @@ metrics-core ${metrics.version} + + io.dropwizard.metrics + metrics-jvm + ${metrics.version} + io.dropwizard.metrics metrics-graphite diff --git a/src/main/java/org/prebid/server/spring/config/MetricsConfiguration.java b/src/main/java/org/prebid/server/spring/config/MetricsConfiguration.java index b6ad9702fe4..1843a12fd4c 100644 --- a/src/main/java/org/prebid/server/spring/config/MetricsConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/MetricsConfiguration.java @@ -6,6 +6,8 @@ import com.codahale.metrics.SharedMetricRegistries; import com.codahale.metrics.graphite.Graphite; import com.codahale.metrics.graphite.GraphiteReporter; +import com.codahale.metrics.jvm.GarbageCollectorMetricSet; +import com.codahale.metrics.jvm.MemoryUsageGaugeSet; import com.izettle.metrics.influxdb.InfluxDbHttpSender; import com.izettle.metrics.influxdb.InfluxDbReporter; import com.izettle.metrics.influxdb.InfluxDbSender; @@ -113,7 +115,12 @@ Metrics metrics(@Value("${metrics.metricType}") CounterType counterType, MetricR @Bean MetricRegistry metricRegistry() { - return SharedMetricRegistries.getOrCreate(METRIC_REGISTRY_NAME); + final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(METRIC_REGISTRY_NAME); + + metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet()); + metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet()); + + return metricRegistry; } @Bean From f1193bdce453a35ae3a94529dbaf07dae8a3d2c1 Mon Sep 17 00:00:00 2001 From: Sergii Chernysh Date: Wed, 25 Nov 2020 14:36:22 +0200 Subject: [PATCH 2/2] Fix metrics registry instantiation in tests --- .../prebid/server/spring/config/MetricsConfiguration.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/prebid/server/spring/config/MetricsConfiguration.java b/src/main/java/org/prebid/server/spring/config/MetricsConfiguration.java index 1843a12fd4c..9e9f1b1db8d 100644 --- a/src/main/java/org/prebid/server/spring/config/MetricsConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/MetricsConfiguration.java @@ -115,10 +115,13 @@ Metrics metrics(@Value("${metrics.metricType}") CounterType counterType, MetricR @Bean MetricRegistry metricRegistry() { + final boolean alreadyExists = SharedMetricRegistries.names().contains(METRIC_REGISTRY_NAME); final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(METRIC_REGISTRY_NAME); - metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet()); - metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet()); + if (!alreadyExists) { + metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet()); + metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet()); + } return metricRegistry; }