From: Simon Brandhof Date: Sun, 24 Sep 2017 20:11:05 +0000 (+0200) Subject: SONAR-9802 add memory and cpu metrics to JvmStateSection X-Git-Tag: 6.6-RC1~207 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7587e6f000c2cbf90c66f2424f3a7f597899d73d;p=sonarqube.git SONAR-9802 add memory and cpu metrics to JvmStateSection --- diff --git a/server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java b/server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java index 804e2f0de5e..b5cf9c90f46 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java +++ b/server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java @@ -22,9 +22,11 @@ package org.sonar.process.systeminfo; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.MemoryUsage; +import java.lang.management.OperatingSystemMXBean; import java.lang.management.ThreadMXBean; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; +import static java.lang.String.format; import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute; /** @@ -47,6 +49,8 @@ public class JvmStateSection implements SystemInfoSection { ProtobufSystemInfo.Section toProtobuf(MemoryMXBean memoryBean) { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName(name); + addAttributeInMb(protobuf,"Max Memory (MB)", Runtime.getRuntime().maxMemory()); + addAttributeInMb(protobuf, "Free Memory (MB)", Runtime.getRuntime().freeMemory()); MemoryUsage heap = memoryBean.getHeapMemoryUsage(); addAttributeInMb(protobuf, "Heap Committed (MB)", heap.getCommitted()); addAttributeInMb(protobuf, "Heap Init (MB)", heap.getInit()); @@ -57,7 +61,8 @@ public class JvmStateSection implements SystemInfoSection { addAttributeInMb(protobuf, "Non Heap Init (MB)", nonHeap.getInit()); addAttributeInMb(protobuf, "Non Heap Max (MB)", nonHeap.getMax()); addAttributeInMb(protobuf, "Non Heap Used (MB)", nonHeap.getUsed()); - + OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); + setAttribute(protobuf,"System Load Average", format("%.1f%% (last minute)", os.getSystemLoadAverage() * 100.0)); ThreadMXBean thread = ManagementFactory.getThreadMXBean(); setAttribute(protobuf, "Threads", thread.getThreadCount()); diff --git a/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java b/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java index 77da5df5719..c2513a418d4 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java @@ -39,7 +39,11 @@ public class JvmStateSectionTest { assertThat(section.getName()).isEqualTo(PROCESS_NAME); assertThat(section.getAttributesCount()).isGreaterThan(0); - assertThat(section.getAttributesList()).extracting("key").contains("Threads", "Heap Max (MB)"); + assertThat(section.getAttributesList()).extracting("key") + .contains( + "Max Memory (MB)", "Free Memory (MB)", + "Heap Max (MB)", + "System Load Average", "Threads"); } @Test