From: danielhanrahan Date: Thu, 23 Jan 2025 15:07:06 +0000 (+0000) Subject: Expose JVM process metrics X-Git-Tag: 3.6.0~14^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=6f9ecc5cfc8ca48df55e4893b403e0d75f4cfc07;p=cps.git Expose JVM process metrics Currently, Grafana only shows memory used inside the JVM, but not including memory used by the JVM process itself. These metrics are needed for determining real memory usage. Issue-ID: CPS-2583 Signed-off-by: danielhanrahan Change-Id: Ib77f9057c7301ea5afc2a621526736213ddd817a --- diff --git a/cps-application/pom.xml b/cps-application/pom.xml index 5ac2202e85..1a46b5fa8a 100644 --- a/cps-application/pom.xml +++ b/cps-application/pom.xml @@ -77,6 +77,10 @@ io.micrometer micrometer-tracing-bridge-otel + + io.github.mweirauch + micrometer-jvm-extras + com.fasterxml.jackson.dataformat jackson-dataformat-xml diff --git a/cps-application/src/main/java/org/onap/cps/config/MicroMeterConfig.java b/cps-application/src/main/java/org/onap/cps/config/MicroMeterConfig.java index d169c61ad6..8481eadf1b 100644 --- a/cps-application/src/main/java/org/onap/cps/config/MicroMeterConfig.java +++ b/cps-application/src/main/java/org/onap/cps/config/MicroMeterConfig.java @@ -21,9 +21,12 @@ package org.onap.cps.config; import com.hazelcast.map.IMap; +import io.github.mweirauch.micrometer.jvm.extras.ProcessMemoryMetrics; +import io.github.mweirauch.micrometer.jvm.extras.ProcessThreadMetrics; import io.micrometer.core.aop.TimedAspect; import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.binder.MeterBinder; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -41,6 +44,16 @@ public class MicroMeterConfig { return new TimedAspect(meterRegistry); } + @Bean + public MeterBinder processMemoryMetrics() { + return new ProcessMemoryMetrics(); + } + + @Bean + public MeterBinder processThreadMetrics() { + return new ProcessThreadMetrics(); + } + /** * Register gauge metric for cm handles with state 'advised'. * diff --git a/cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy b/cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy index fc8c670ebf..b9302ccd72 100644 --- a/cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy +++ b/cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy @@ -31,10 +31,17 @@ class MicroMeterConfigSpec extends Specification { def simpleMeterRegistry = new SimpleMeterRegistry() def 'Creating a timed aspect.'() { - expect: ' a timed aspect can be created' + expect: 'a timed aspect can be created' assert objectUnderTest.timedAspect(simpleMeterRegistry) != null } + def 'Creating JVM process metrics.'() { + expect: 'process memory metrics can be created' + assert objectUnderTest.processMemoryMetrics() != null + and: 'process thread metrics can be created' + assert objectUnderTest.processThreadMetrics() != null + } + def 'Creating gauges for cm handle states.'() { given: 'cache returns value for each state' cmHandlesByState.get(_) >> 1 diff --git a/cps-dependencies/pom.xml b/cps-dependencies/pom.xml index bf9ba00937..62fa154611 100644 --- a/cps-dependencies/pom.xml +++ b/cps-dependencies/pom.xml @@ -172,6 +172,11 @@ pom import + + io.github.mweirauch + micrometer-jvm-extras + 0.2.2 + io.gsonfire gson-fire