Expose JVM process metrics 16/140016/1
authordanielhanrahan <daniel.hanrahan@est.tech>
Thu, 23 Jan 2025 15:07:06 +0000 (15:07 +0000)
committerdanielhanrahan <daniel.hanrahan@est.tech>
Thu, 23 Jan 2025 15:59:20 +0000 (15:59 +0000)
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

cps-application/pom.xml
cps-application/src/main/java/org/onap/cps/config/MicroMeterConfig.java
cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy
cps-dependencies/pom.xml

index 5ac2202..1a46b5f 100644 (file)
             <groupId>io.micrometer</groupId>
             <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>
index d169c61..8481ead 100644 (file)
 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'.
      *
index fc8c670..b9302cc 100644 (file)
@@ -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
index bf9ba00..62fa154 100644 (file)
                 <type>pom</type>
                 <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>