diff options
author | 2025-01-23 15:07:06 +0000 | |
---|---|---|
committer | 2025-01-23 15:59:20 +0000 | |
commit | 6f9ecc5cfc8ca48df55e4893b403e0d75f4cfc07 (patch) | |
tree | b7c65c91167100fd927d3e7c3e7fdeda36436177 | |
parent | 31d8f390389b9078a2f0cddca3f4b4b1cd63753a (diff) |
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 <daniel.hanrahan@est.tech>
Change-Id: Ib77f9057c7301ea5afc2a621526736213ddd817a
4 files changed, 30 insertions, 1 deletions
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 @@ -78,6 +78,10 @@ <artifactId>micrometer-tracing-bridge-otel</artifactId> </dependency> <dependency> + <groupId>io.github.mweirauch</groupId> + <artifactId>micrometer-jvm-extras</artifactId> + </dependency> + <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> </dependency> 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 @@ -173,6 +173,11 @@ <scope>import</scope> </dependency> <dependency> + <groupId>io.github.mweirauch</groupId> + <artifactId>micrometer-jvm-extras</artifactId> + <version>0.2.2</version> + </dependency> + <dependency> <groupId>io.gsonfire</groupId> <artifactId>gson-fire</artifactId> <version>1.9.0</version> |